我如何使用 gridview 链接按钮的 Jquery ui 对话框确认?

发布于 2024-12-28 23:46:52 字数 977 浏览 3 评论 0原文

我在 Gridview 中有一个用于删除项目的链接按钮。我想使用(jquery ui 对话框确认)与此按钮。

      <asp:LinkButton ID="lnkDelete" Font-Size="12px" runat="server" CausesValidation="False" CommandName="Delete" Text="Sil"></asp:LinkButton>

我可以像这样使用 jquery ui 对话框确认:(asp.button)

      function onayMesaj(msg) {
                    $("#divMesaj").html(msg);
              $("#divMesaj").dialog({
                  modal: true,
                  bgiframe: true,
                  buttons: {
                      "Yes": function () {
                         <%=this.Page.ClientScript.GetPostBackEventReference(new PostBackOptions(this.btnGuncelleEkle))%>;
                      },
                       "No": function () {
                          $(this).dialog("close");
                      }
                  }
              });
              $("#divMesaj").parent().appendTo($("form:first"));
          }

我被卡住了。请帮忙。谢谢。

I have a linkbutton in Gridview for delete items. I wanna use (jquery ui dialog confirmation) with this button.

      <asp:LinkButton ID="lnkDelete" Font-Size="12px" runat="server" CausesValidation="False" CommandName="Delete" Text="Sil"></asp:LinkButton>

I could use jquery ui dialog confirmation before like this: (asp.button)

      function onayMesaj(msg) {
                    $("#divMesaj").html(msg);
              $("#divMesaj").dialog({
                  modal: true,
                  bgiframe: true,
                  buttons: {
                      "Yes": function () {
                         <%=this.Page.ClientScript.GetPostBackEventReference(new PostBackOptions(this.btnGuncelleEkle))%>;
                      },
                       "No": function () {
                          $(this).dialog("close");
                      }
                  }
              });
              $("#divMesaj").parent().appendTo($("form:first"));
          }

I'm stuck. Please help. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

洒一地阳光 2025-01-04 23:46:52

我能够通过以下帖子来实现此解决方案: http://www.junnark.com/Blog /Detail/13

基本上,您的删除按钮应该是这样的:

<asp:ImageButton ID="IBtnDelete" runat="server" CommandArgument='<%#Eval("idcustomer")%>' 
    OnClientClick="javascript:return deleteItem(this.name, this.alt);"
    ToolTip="Click to delete" ImageUrl="~/Images/imagesActions/delete_action.png"
    AlternateText='<%#Eval("name")%>' OnCommand="deleteCommand" />

您的 javascript 函数应该是这样的:

function deleteItem(uniqueID, customerID) {
    var dialogTitle = 'Permanently delete ' + customerID + '?';   
    $('#' + '<%=linkDelete.ClientId %>').html('<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Please click delete to confirm deletion.</p>');
    $('#' + '<%=linkDelete.ClientId %>').dialog({
        title: dialogTitle,
        buttons: {
            "Delete": function () { __doPostBack(uniqueID, ''); $(this).dialog("close"); },
            "Cancel": function () { $(this).dialog("close"); }
        }
    });

    $('#' + '<%=linkDelete.ClientId %>').dialog('open');
    return false;
}

并且,在您的代码隐藏中,您应该有删除所选项目的命令。像这样的事情:

protected void deleteCommand(object sender, CommandEventArgs e)
    {
        customerDA cus = new customerDA();
        cus.deleteCustomer(Convert.ToInt32(e.CommandArgument.ToString()));
    }

就是这样。希望这有帮助!

I was able to implement this solution by following this post: http://www.junnark.com/Blog/Detail/13

Basically, your delete button should be something like this:

<asp:ImageButton ID="IBtnDelete" runat="server" CommandArgument='<%#Eval("idcustomer")%>' 
    OnClientClick="javascript:return deleteItem(this.name, this.alt);"
    ToolTip="Click to delete" ImageUrl="~/Images/imagesActions/delete_action.png"
    AlternateText='<%#Eval("name")%>' OnCommand="deleteCommand" />

Your javascript function should be something like this:

function deleteItem(uniqueID, customerID) {
    var dialogTitle = 'Permanently delete ' + customerID + '?';   
    $('#' + '<%=linkDelete.ClientId %>').html('<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Please click delete to confirm deletion.</p>');
    $('#' + '<%=linkDelete.ClientId %>').dialog({
        title: dialogTitle,
        buttons: {
            "Delete": function () { __doPostBack(uniqueID, ''); $(this).dialog("close"); },
            "Cancel": function () { $(this).dialog("close"); }
        }
    });

    $('#' + '<%=linkDelete.ClientId %>').dialog('open');
    return false;
}

And, in your codebehind, you should have the command to delete the selected item. Something like this:

protected void deleteCommand(object sender, CommandEventArgs e)
    {
        customerDA cus = new customerDA();
        cus.deleteCustomer(Convert.ToInt32(e.CommandArgument.ToString()));
    }

That's it. Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文