asp.netgridview

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


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


Solution

  • This code from a 2008 post by the user rtpHarry on the ASP.NET forums should do it:

    <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>