且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过Java脚本/VB脚本在gridview中删除行之前如何显示确认对话框

更新时间:2023-02-06 18:49:48

在命令"按钮中添加确认对话框选中此链接.
使用asp:CommandField的GridView删除确认 [
Adding confirm dialog box in Command buttons Check this link.

GridView Delete Confirmation Using asp:CommandField[^]


<asp:ImageButton ID="btnDelete" runat="server" CausesValidation="False" CommandName="Delete" ImageUrl="~/Image/delete.png" OnClick="btnDelete_Click" Text="Delete"
OnClientClick="return confirm('Are you sure you want to Delete this record ?')" />


朋友,
看到我有你的解决方案.
只是尝试这个.

设计如下所述的网格
hi friend,
see i have solution for u.
just try this.

Design your grid mentioned as below
<asp:templatefield showheader="False" xmlns:asp="#unknown">
     <itemtemplate>
          <asp:linkbutton id="lnkBtn" commandname="Delete" text="Delete" onclientclick="return ConfirmDelete();">
runat="server">Delete</asp:linkbutton>
     </itemtemplate>
</asp:templatefield>



将此Java脚本添加到您的aspx表单中



Add this java script into your aspx form

function ConfirmDelete()
{
    var Delet_Confirm= confirm("Do you really want to delete this record ?");
 if (Delet_Confirm== true)
 {
   return true;
 }
 else
 {
  return false;
  }
}




如果您不使用模板字段,则可以将相同的Java脚本写入
通过定义< javascript>将网格的行命令事件转换为.cs文件.标签.


谢谢,
Mahesh Patel




if you are not using template field, you can write same java script into
row command event of grid into .cs file by define <javascript> tag.


Thanks,
Mahesh Patel