开发者

Display Text when Delete button is clicked in GridView

开发者 https://www.devze.com 2023-02-21 18:13 出处:网络
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 d

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


Try this:

http://www.codeproject.com/KB/webforms/GridViewConfirmDelete.aspx


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消