Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a "confirm delete" option in ASP.Net Gridview?

How to add a "confirm delete" option in ASP.Net Gridview ?

like image 352
Mohamed Kamal Avatar asked Jan 25 '11 13:01

Mohamed Kamal


2 Answers

This should do it.

I found it here: http://forums.asp.net/p/1331581/2678206.aspx

<asp:TemplateField ShowHeader="False">
    <ItemTemplate>
        <asp:ImageButton ID="DeleteButton" runat="server" ImageUrl="~/site/img/icons/cross.png"
                    CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete this event?');"
                    AlternateText="Delete" />               
    </ItemTemplate>
</asp:TemplateField>  
like image 176
statmaster Avatar answered Sep 21 '22 07:09

statmaster


If your Gridview used with AutoGenerateDeleteButton="true" , you may convert it to LinkButton:

  1. Click GridView Tasks and then Edit Columns. https://www.flickr.com/photos/32784002@N02/15395933069/

  2. Select Delete in Selected fields, and click on Convert this field into a TemplateField. Then click OK: https://www.flickr.com/photos/32784002@N02/15579904611/

  3. Now your LinkButton will be generated. You can add OnClientClick event to the LinkButton like this:
    OnClientClick="return confirm('Are you sure you want to delete?'); "

like image 29
Ilkin Sam Elimov Avatar answered Sep 23 '22 07:09

Ilkin Sam Elimov