2010-03-17 11 views
0

當我嘗試將數據綁定'<%#Eval("EntryID") %>'到的ImageButton的一項PostBackUrl爲想要在gridview中的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 
+0

你可以顯示你正在做數據綁定的代碼? – 2010-03-17 07:00:09

+0

通過製作函數,在頁面加載事件上的codebehind上進行數據綁定。 – sikender 2010-03-17 07:13:58

回答

1

應該是這樣......

PostBackUrl='<%# Eval("SystemEmailID", "Edit_SyatemEmails.aspx?id={0}" 
+ "&blogentry=" + Request.QueryString["edit"]) %>' 
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")) 
    } 
} 
相關問題