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?"
Gaurav GuptaPosted Apr 16, 2013, 1:31 AM
<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.