在gridview中删除数据之前询问确认 [英] ask confirmation before deleting data in gridview

查看:78
本文介绍了在gridview中删除数据之前询问确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友



当我们点击默认gridview中的删除按钮时它首先会要求确认后它会删除。



如果我们在页脚中有删除按钮意味着通过onclient click命令我们可以在删除之前使用警报..



电话我该怎么办?

hello friends

when we click delete button in default gridview first it asks confirmation after that it ll delete.

if we are having delete button in footer means by onclient click command we can use alert before delteting..

tel me how to do?

推荐答案

试试这个:



try this:

<asp:Button ID="DeleteButton" runat="server" OnClientClick="return confirm('Are you sure you want to delete this ?');" Font-Bold="True" Font-Size="Large" ForeColor="Blue"
        OnClick="DeleteButton_Click" Text="Delete" ToolTip="Click here to Delete this....."
        ValidationGroup="MyPersonal" Width="98px" />







并在DeleteButton_Click事件中用C#编写删除代码..




and in DeleteButton_Click event write your deleting code in C#..


要添加删除提示,您需要绑定JavaScript以提示数据网格的 ItemDataBound 事件期间的此警报(或Gridview的 RowDatabound )。



在这种情况下,当数据逐行绑定时 - 添加如下内容:

For adding a delete prompt, you would need to bind the JavaScript to prompt for this alert during the ItemDataBound event of the datagrid (or RowDatabound of Gridview).

In this event, while the data is binded row by row - add something like:
LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1"); 
l.Attributes.Add("onclick", "javascript:return " +
    "confirm('Are you sure you want to delete this record')"); 

或者,

如果datagrid的ItemTemplate中的链接按钮暴露了OnclientClick事件(在ASP.NET2.0以后出现),你可以添加如下内容: />

Alternatively,
if the link button in ItemTemplate of datagrid has OnclientClick event exposed (which is present in ASP.NET2.0 onwards), you can add something like:

OnClientClick = 'return confirm("Are you sure you want to delete this entry?");' 





试试!



Try!


您好初学者在C#.net,



Hi beginner in C#.net,

DialogResult result = MessageBox.Show("Are you sure you want to delete ?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
    // write the code to delete here
}





我希望这个帮助,

:)



I hope this help,
:)


这篇关于在gridview中删除数据之前询问确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆