从网格视图删除之前的消息框 [英] Message box before deleting from grid view
本文介绍了从网格视图删除之前的消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我有一个包含编辑和删除按钮的数据库表的网格视图.如果用户单击一行的删除"按钮,我想问他/她:确定吗?"在带有两个按钮的消息框中(是/否).
我该怎么做?
Hallo,
I have a grid view of a database table including edit- and delete- buttons. If the user clicks the delete button of a row, I want to ask him/her, "Are you sure?" in a messagebox with two buttons (yes/no).
How can I do that?
推荐答案
<ItemTemplate>
<asp:LinkButton ID="btn_Cancel" runat="server" Text="Cancel" CommandName="cancel" OnClientClick="return confirm('Are you sure want to delete this record?')" />
</ItemTemplate>
请参见讨论
在ASP.Net中确认框
See the Discussion
Confirm box in ASP.Net
它可能会为您提供帮助.
it may helps you.
<asp:Button runat="server" ID="lnkDelete" CausesValidation="False" Text="Delete"
OnClientClick="chkDelete();" CommandName="Delete" ></asp:Button>
然后插入一个HiddenField控件
then insert a HiddenField control
<asp:hiddenfield id="hdelete" runat="server" value="0" xmlns:asp="#unknown" />
写这个脚本
write this script
<script type="text/javascript">
function chkDelete()
{
if(confirm("Do u want Delete?"))
{
document.getElementById("ctl00_ContentPlaceHolder1_GridView2_ctl02_hdelete").value="1";
}
else
{
document.getElementById("ctl00_ContentPlaceHolder1_GridView2_ctl02_hdelete").value="0";
}
}
</script>
然后在row_deleteing事件中,
then in row_deleteing event,
int str = Convert.ToInt32(((HiddenField)GridView2.Rows[0].FindControl("hdelete")).Value);
if (str == 0)
{
e.Cancel = true;
}
else
{
e.Cancel = false;
// write code for delete
}
问候,
Palraj
Regards,
Palraj
这篇关于从网格视图删除之前的消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文