C# .NET - postbackurl in imagebutton in repeater

Asked By deepi singh on 10-Aug-11 02:35 AM

<asp:imagebutton id="img1" runat="server"  postbackurl='AddEdit.aspx?ID=<%# DataBinder.Eval(Container.DataItem,"ID") %>&ReturnUrl=List.aspx'></asp:imagebutton>

i want to keep tht postbackurl with query string in  repater intembound in codebehind file not in aspx file

protected void rptFootnote_ItemBound(Object Sender, RepeaterItemEventArgs e)

{

----how to place here postback url with quey string?
}


}

dipa ahuja replied to deepi singh on 10-Aug-11 02:49 AM
Hi..

Change your code this way:

<asp:ImageButton ID="ImageButton1" Height="20" Width="10" ImageUrl="~/1.bmp" 
PostBackUrl='<%# DataBinder.Eval(Container.DataItem, "ID", "Page2.aspx?ID={0}") %>'
runat="server" />
deepi singh replied to dipa ahuja on 10-Aug-11 03:16 AM
i want to do in cs file(repeater_itembound event) not in aspx
dipa ahuja replied to deepi singh on 10-Aug-11 04:35 AM
ok then implement the ItemCommand event:


Markup:

<asp:Label ID="lblid" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "ID")%>' />
<br />
<asp:ImageButton ID="ImageButton1" Height="20" Width="10" CommandName="Click"
ImageUrl="~/1.bmp" runat="server" />

CodeBehind:

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
  if (e.CommandName == "Click")
  {
    RepeaterItem item = (RepeaterItem)(((ImageButton)e.CommandSource).NamingContainer);
    string id = ((Label)item.FindControl("lblid")).Text;
    Response.Redirect("Querystringget.aspx?id=" + id);
  }
}