【问题标题】:Want to bind querystring in postbackurl of imagebutton in gridview?想要在 gridview 中的 imagebutton 的 postbackurl 中绑定查询字符串?
【发布时间】:2010-03-17 06:57:17
【问题描述】:

当我尝试将 '<%#Eval("EntryID") %>' 数据绑定到 ImageButton 的 postbackurl 时

<asp:ImageButton ID="ibtnEdit" runat="server" CommandName="Edit" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"SystemEmailID")%>'
  ImageUrl="~/Images/edit-list.gif" PostBackUrl="~/Edit_SyatemEmails.aspx?blogentry=edit&id=<%#DataBinder.Eval(Container.DataItem,"SystemEmailID")%>"/>

it's failed, then i updated the code to

 <asp:ImageButton ID="ibtnBlogEntryEdit" PostBackUrl='"~/admin/BlogEntry.aspx?blogentry=edit&entryid=" & <%# Eval("EntryID") %>' SkinID="edit" runat="server" />

 well,the above code has pass the debugging,but failed to databind to the postbackurl,the result as  

http://localhost/dovoshow/"~/admin/BlogEntry.aspx?blogentry=edit&entryid="%20&%20<%#%20Eval("EntryID")%20%>

so,anyonw know how to solve it ,help me  thanks 

【问题讨论】:

  • 你能在你做数据绑定的地方显示代码吗?
  • 通过创建函数在页面加载事件的代码隐藏处进行数据绑定。

标签: c# asp.net gridview query-string


【解决方案1】:

应该是……

PostBackUrl='<%# Eval("SystemEmailID", "Edit_SyatemEmails.aspx?id={0}"
 + "&blogentry=" + Request.QueryString["edit"]) %>'

【讨论】:

    【解决方案2】:

    我建议您在后面的代码中执行此操作。 在 GridView RowCreated 事件上:

    protected void GridView_OnRowCreated(Object sender, GridViewRowEventArgs e)
    {
        if(e.Row.RowType == DataControlRowType.DataRow)
        {
          (e.Row.FindControl("ibtnEdit") as ImageButton). PostBackUrl = "~/Edit_SyatemEmails.aspx?blogentry=edit&id=" + DataBinder.Eval(e.Row.DataItem, "SystemEmailID"))
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-02
      • 2015-11-19
      • 2020-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-06
      • 1970-01-01
      相关资源
      最近更新 更多