Delete confirmation in Gridview in asp.net

ASP.NET Comments Off on Delete confirmation in Gridview in asp.net

Hi all, Just thought to keep this snippet handy. When you create a gridview from a table and you add delete command in it. Whenever you click the delete command or link , the record gets deleted immediately. If there is a javascript popup confirmation so that you can confirm again to delete it that would be nice.

It is simple just convert the delete command coloumn to a template field, this will add the link button. And add code to the OnClientClick event as shown.


<asp:TemplateField HeaderText="Click to Delete" ShowHeader="False">

<ItemTemplate>
 <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
 CommandName="Delete" Text="Delete" OnClientClick='return confirm("Do you want to delete this record?");'></asp:LinkButton>
 </ItemTemplate>
 </asp:TemplateField>



Author

Search

Back to Top