How do I pop up a delete confirm for a delete button in an asp:GridView?
If you have a delete button for each row in a GridView, here is what I think is the best (and definitely easiest) way to have it put up an alert asking for confirmation. Here is the full aspx code (there is no code-behind needed):
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="DeleteButton" runat="server"
CausesValidation="False"
CommandName="Delete"
OnClientClick='<%# Eval("Title", "return confirm(\"Delete the datasource {0}?\");") %>'
Text="delete" />
</ItemTemplate>
</asp:TemplateField>
A couple of notes:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With