Reputation: 1418
I have a Gridview., usually, when the delete command button is clicked then the row will be deleted., But what should I do if I want a alert message like "Are you sure......." to be displayed..... Any Ideas please
Thanks
Upvotes: 0
Views: 1461
Reputation: 4546
Just before doing the delation (the way you do) use messageBox with DialogResult object. If the user agrees with delation do the delation, if not, return:
if (DialogResult.Yes == MessageBox.Show("You want to delate the row?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
{
//delete the row!
}
You dont actually do anything if he selects No. The code will not execute anything.
Upvotes: 1
Reputation: 3338
Try this:
http://www.codeproject.com/KB/webforms/GridViewConfirmDelete.aspx
Upvotes: 1
Reputation: 31610
You can do this easily via a template column:
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="btnDelete" runat="server" CausesValidation="False" CommandName="Delete"
OnClientClick='return confirm("Are you sure you want to delete?");'
Text="Delete" />
</ItemTemplate>
</asp:TemplateField>
Upvotes: 1