pinki
pinki

Reputation: 1418

Display Text when Delete button is clicked in GridView

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

Answers (3)

Mitja Bonca
Mitja Bonca

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

Ta01
Ta01

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

Related Questions