For this you need to use asp:linkbutton
CODE For Gridview in test.aspx file is
<asp:gridview id="gv_test" onrowdatabound="gv_test_OnRowDataBound" runat="server" >
< columns >
< asp:templatefield headertext="Delete" >
< itemtemplate >
< asp:linkbutton commandargument='<%# Eval("id") %>' commandname="cmdDelete" id="btnDelete" onclientclick="javascript: return confirm('do u want to delete this record')" runat="server" > DELETE </ asp:linkbutton >
</ itemtemplate >
</ asp:templatefield >
</ columns >
CODE for gv_test_OnRowDataBound Method in test.aspx.cs File is
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
//Through command Name link Button will be identified.
if (e.CommandName == "cmdDelete")
{
// This is id which you can use for DELETE purpose.
string id = e.CommandArgument;
}
}
Using above code you can get confirm before Delete in GRIDVIEW as given below:
No comments:
Post a Comment