显示消息框的命令字段

2024-05-14

我有一个像这样的命令字段,

<asp:CommandField ShowEditButton="true" ShowDeleteButton="True" ItemStyle-Width="10px" />

现在在删除时我想显示一个确认框,但不知道该怎么做。

抱歉,我不想使用模板字段。

也许我可以使用 JS 来显示消息,或者在这个代码隐藏方法中,

 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)

我试过这个,

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        //In this sample, there are  3 buttons and the second one is Delete button, that's why we use the index 2
        //indexing goes as 0 is button #1, 1 Literal (Space between buttons), 2 button #2, 3 Literal (Space) etc.
        ((Button)e.Row.Cells[0].Controls[2]).OnClientClick = "return confirm('"Do you really want to delete?');";
    }
}

但我的索引超出范围,因为那里没有任何控制。SOURCE http://forums.asp.net/t/1045957.aspx/1

这是我的 GridView 的完整代码,我更改了列的名称和其他文本,所以不要感到困惑,

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:GridView ID="GridView1" runat="server" DataKeyNames="UserID" AutoGenerateColumns="false"
            CellPadding="5" OnRowDataBound="GridView1_RowDataBound" Width="800px" AllowPaging="True"
            PageSize="5" GridLines="Horizontal" OnPageIndexChanging="GridView1_PageIndexChanging"
            OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDeleting="GridView1_RowDeleting"
            OnRowUpdating="GridView1_RowUpdating" OnRowEditing="GridView1_RowEditing">
            <Columns>
                <asp:TemplateField ItemStyle-Width="8px" ControlStyle-Width="8px">
                    <ItemTemplate>
                        <a href="javascript:switchViews('div<%# Eval("UserID") %>', 'one');">
                            <img id="imgdiv<%# Eval("UserID") %>" alt="Click to show/hide orders" border="0"
                                src="/_layouts/g1.png" />
                        </a>
                    </ItemTemplate>
                    <AlternatingItemTemplate>
                        <a href="javascript:switchViews('div<%# Eval("UserID") %>', 'alt');">
                            <img id="imgdiv<%# Eval("UserID") %>" alt="Click to show/hide orders" border="0"
                                src="/_layouts/g1.png" />
                        </a>
                    </AlternatingItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="UserID" ReadOnly="true" HeaderText="User ID" ItemStyle-Width="120px" />
                <asp:BoundField DataField="Name" HeaderText="User Name" ItemStyle-Width="350px" />
                <asp:BoundField DataField="City" HeaderText="City" ItemStyle-Width="800px" />
                <asp:CommandField ShowEditButton="true" ShowDeleteButton="True" ItemStyle-Width="10px" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <tr>
                            <td colspan="100%">
                                <div id="div<%# Eval("UserID") %>" style="display: none; position: relative;
                                    left: 25px;">
                                    <asp:GridView ID="GridView2" runat="server" Width="80%" AutoGenerateColumns="false"
                                        DataKeyNames="TTTT" EmptyDataText="There isn't e.">
                                        <Columns>
                                            <asp:HyperLinkField HeaderText="TTTT Title" DataNavigateUrlFields="anotherfield"
                                                DataTextField="TTTT" DataTextFormatString="{0:c}" Target="_blank" />
                                            <asp:BoundField DataField="orDerDescription" HeaderText="orDerDescription" HtmlEncode="False" />
                                        </Columns>
                                    </asp:GridView>
                                </div>
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>

当我尝试回答时出错


如果删除 CommandField 位于网格视图的第二列

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {

        LinkButton link = (LinkButton)e.Row.Cells[4].Controls[2];
        if (link != null)
        {
            link.OnClientClick = "return confirm('Do you really want to delete?')";
        }
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

显示消息框的命令字段 的相关文章

  • 不可勾选的单选按钮与专有的复选框

    从 UI 角度来看 是拥有一组具有取消选中功能的单选按钮更好 还是拥有一组独占的复选框 意味着一次只能选中一个 更好 Update 我没想到对此会有如此负面的反应 如果我给出一个更接近其使用方式的示例 也许会有所帮助 我有一个充满数据绑定内
  • 重载<<的返回值

    include
  • 显示UnityWebRequest的进度

    我正在尝试使用下载 assetbundle统一网络请求 https docs unity3d com ScriptReference Networking UnityWebRequest GetAssetBundle html并显示进度 根
  • SolrNet连接说明

    为什么 SolrNet 连接的容器保持静态 这是一个非常大的错误 因为当我们在应用程序中向应用程序发送异步请求时 SolrNet 会表现异常 在 SolrNet 中如何避免这个问题 class P static void M string
  • 如何在整个 ASP .NET MVC 应用程序中需要授权

    我创建的应用程序中 除了启用登录的操作之外的每个操作都应该超出未登录用户的限制 我应该添加 Authorize 每个班级标题前的注释 像这儿 namespace WebApplication2 Controllers Authorize p
  • Javascript 假值(null、未定义、false、空字符串:“”或 '' 和 0)和比较(==)运算符 [重复]

    这个问题在这里已经有答案了 当我使用任何一个值时 null undefined false 0 in a if陈述 它总是被评估为谬误 false 另外 这些值的否定 null undefined false 0 in a if语句总是被评
  • Firebase 函数 onWrite 未被调用

    我正在尝试使用 Firebase 函数实现一个触发器 该触发器会复制数据库中的一些数据 我想观看所有添加的内容votes user vote 结构为 我尝试的代码是 const functions require firebase func
  • 正则表达式 - 从 markdown 字符串中提取所有标题

    我在用灰质 https www npmjs com package gray matter 以便将文件系统中的 MD 文件解析为字符串 解析器产生的结果是这样的字符串 n Clean er ReactJS Code Conditional
  • 如何序列化/反序列化自定义数据集

    我有一个 winforms 应用程序 它使用强类型的自定义数据集来保存数据进行处理 它由数据库中的数据填充 我有一个用户控件 它接受任何自定义数据集并在数据网格中显示内容 这用于测试和调试 为了使控件可重用 我将自定义数据集视为普通的 Sy
  • 什么时候虚拟继承是一个好的设计? [复制]

    这个问题在这里已经有答案了 EDIT3 请务必在回答之前清楚地了解我要问的内容 有 EDIT2 和很多评论 有 或曾经 有很多答案清楚地表明了对问题的误解 我知道这也是我的错 对此感到抱歉 嗨 我查看了有关虚拟继承的问题 class B p
  • Three.js 各种大小的粒子

    我是 Three js 的新手 正在尝试找出添加 1000 个粒子的最佳方法 每个粒子都有不同的大小和颜色 每个粒子的纹理是通过绘制画布创建的 通过使用粒子系统 所有粒子都具有相同的颜色和大小 为每个粒子创建一个粒子系统是非常低效的 有没有
  • 使用 x509 证书签署 json 文档或字符串

    如何使用 x509 证书签署 json 文档或字符串 public static void fund string filePath C Users VIKAS Desktop Data xml Read the file XmlDocum
  • 如何将带有 IP 地址的连接字符串放入 web.config 文件中?

    我们当前在 web config 文件中使用以下连接字符串 add name DBConnectionString connectionString Data Source ourServer Initial Catalog ourDB P
  • 在 Shopify 商店中嵌入 Vue 组件

    在产品页面中 我尝试显示自定义 Vue 组件 为简洁起见 该组件根据给定的产品 ID 显示 Firebase 数据库中的一些信息 我最初尝试将其制作为 Shopify 应用程序 以便我可以访问他们的 API 我实现了 OAuth 并且可以检
  • C# 成员变量继承

    我对 C 有点陌生 但我在编程方面有相当广泛的背景 我想做的事情 为游戏定义不同的 MapTiles 我已经像这样定义了 MapTile 基类 public class MapTile public Texture2D texture pu
  • 基于 OpenCV 边缘的物体检测 C++

    我有一个应用程序 我必须检测场景中某些项目的存在 这些项目可以旋转并稍微缩放 更大或更小 我尝试过使用关键点检测器 但它们不够快且不够准确 因此 我决定首先使用 Canny 或更快的边缘检测算法 检测模板和搜索区域中的边缘 然后匹配边缘以查
  • 带参数的事件监听器

    我想将参数传递给 JavaScript 中的事件侦听器 我已经找到了解决方案 但我无法理解它们为什么或如何工作以及为什么其他解决方案不起作用 我有 C C 背景 但是 Javascript 函数的执行有很大不同 您能否帮助我理解以下示例如何
  • 如何用另一个响应替换窗口的 URL 哈希?

    我正在尝试使用替换方法更改哈希 URL document location hash 但它不起作用 function var anchor document location hash this returns me a string va
  • Windows 和 Linux 上的线程

    我在互联网上看到过在 Windows 上使用 C 制作多线程应用程序的教程 以及在 Linux 上执行相同操作的其他教程 但不能同时用于两者 是否存在即使在 Linux 或 Windows 上编译也能工作的函数 您需要使用一个包含两者的实现
  • 使用 MongoDB 和 Nodejs 插入和查询日期

    我需要一些帮助在 mongodb 和 nodejs 中按日期查找记录 我将日期添加到抓取脚本中的 json 对象 如下所示 jsonObj last updated new Date 该对象被插入到 mongodb 中 我可以看到如下 la

随机推荐