【问题标题】:How to show ID in message box?如何在消息框中显示 ID?
【发布时间】:2017-01-20 03:29:17
【问题描述】:

我目前正在开发一个网站。我的外部 js 文件中有一个代码

function DeleteConfirm(rfqcodeLB) {
    var confirm_value = document.createElement("INPUT");
    confirm_value.type = "hidden";
    confirm_value.name = "confirm_value";
    if (confirm("Are you sure you want to delete" + rfqcodeLB +" ?")) {
        confirm_value.value = "Yes";
    } else {
        confirm_value.value = "No";
    }
    document.forms[0].appendChild(confirm_value);
}

我想要做的是在gridview 中获取所选行的id。我所做的是将选定的代码转换为 rfqcodeLB 字符串。然后把属性放到按钮上。但它显示为空。

有人可以帮帮我吗?谢谢。

<asp:ImageButton ImageUrl="../Pictures/Icons/deleteblack.png" runat="server" OnClick="Unnamed_Click" ID="deleteBT" OnClientClick="return DeleteConfirm(ContentPlaceHolder1_rfqcodeLB);"/>

【问题讨论】:

    标签: javascript c# asp.net gridview messagebox


    【解决方案1】:

    将id作为函数参数传递,而不是ContentPlaceHolder1_rfqcodeLB,使用this.id。

    【讨论】:

    • 这只会让您获得 ImageButton 的 ID,而不是所选行的 ID。
    【解决方案2】:

    您需要将RowIndex 发送到JavaScript 函数。不是this.id,这只会让您获得 ImageButton 的 ID。

    <asp:ImageButton OnClientClick='<%# "return DeleteConfirm(" + Container.DataItemIndex + ");" %>' ImageUrl="../Pictures/Icons/deleteblack.png" runat="server" OnClick="Unnamed_Click" ID="deleteBT"/>
    

    或者如果你想要一个数据库值

    OnClientClick='<%# "return DeleteConfirm(&#39;" + Eval("yourID") + "&#39;);" %>'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-11
      • 2017-08-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-25
      • 1970-01-01
      相关资源
      最近更新 更多