简体   繁体   中英

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

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM