How to use delete Image button on gridview
I am new to asp.net. I want to use delete image button in gridview. How I can use image button for delete operation in asp.net? Also when user press that button firstly warning should be displayed to user like "are you sure to delete the record?"
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Gaurav GuptaRank #123 · 17.8K reputationPosted Apr 15, 2013, 9:31 PM EDT
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:ImageButton ID="imageButtonDelete" ImageUrl="~/images/btn_delete.gif" OnClientClick="javascript:return confirm('Are you sure you want to delete?');"
Text="Delete" CommandName="Delete" runat="server" />
ItemTemplate>
asp:TemplateField>
Then in the gridview rowcommant event you can put your deleted code in .cs file.
protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
Put code here--------
}
catch (Exception ex)
{
}
}
}
---------------------------------------------------------------------------------------------
If this post helps you then, Mark it as Accepted
Thanks.