想在gridview中的imagebutton的postbackurl中绑定查询字符串吗?

时间:2010-03-17 06:57:18

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

当我尝试将'<%#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 

2 个答案:

答案 0 :(得分:1)

应该是......

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

答案 1 :(得分:1)

我建议你在后面的代码中做到这一点。 在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"))
    }
}