owl

Thursday, September 10, 2009

To Bind A value from database to button and using that value to redirect in code behind file

Using OnCommand in Button

.aspx page
--------------
<asp:ImageButton ID="img01" runat="server" ImageUrl="~/Images/edit_j_btn.jpg" OnCommand="onEdit_Click" CommandArgument='<%#Eval("UserId") %>' />

code behind
--------------
public void onEdit_Click(object sender,System.Web.UI.WebControls.CommandEventArgs e)
{
int userid= Convert.ToInt32(e.CommandArgument);
Response.Redirect("Home.aspx?_UserId=" + userid);
}

No comments: