C# CommandRow LinkBut​​ton 添加 Javascript

发布于 2025-01-02 03:59:29 字数 971 浏览 3 评论 0原文

我使用以下 C# 替换 GridView 命令行中的文本“编辑、删除和选择”。

我想通过使用 javascript“确认”对话框来改进这一点,让用户在删除行之前仔细检查。如何从 LinkBut​​ton 对象执行此操作?

private void commandIcons(GridViewRow row)
{
    if (row.Cells[0].Controls.Count == 5)
    {
        // we have a edit delete select control row type, replace text labels with icons
        LinkButton lbedit = (LinkButton)row.Cells[0].Controls[0];
        lbedit.Text = lbedit.Text == "Edit" ? "<img title=\"Edit\" class=\"icon\" src=\"Images/database_edit.png\" />" : lbedit.Text;

        LinkButton lbdelete = (LinkButton)row.Cells[0].Controls[2];
        lbdelete.Text = lbdelete.Text == "Delete" ? "<img title=\"Delete\" class=\"icon\" src=\"Images/delete.png\" />" : lbdelete.Text;

        LinkButton lbselect = (LinkButton)row.Cells[0].Controls[4];
        lbselect.Text = lbselect.Text == "Select" ? "<img title=\"Select\" class=\"icon\" src=\"Images/accept.png\" />" : lbselect.Text;
    }
}

I am using the following C# to replace the texts 'Edit, Delete and Select' from the command row on GridViews.

I want to improve this by using a javascript 'confirm' dialogue to make the user double check before deleting a row. How can I do this from the LinkButton object?

private void commandIcons(GridViewRow row)
{
    if (row.Cells[0].Controls.Count == 5)
    {
        // we have a edit delete select control row type, replace text labels with icons
        LinkButton lbedit = (LinkButton)row.Cells[0].Controls[0];
        lbedit.Text = lbedit.Text == "Edit" ? "<img title=\"Edit\" class=\"icon\" src=\"Images/database_edit.png\" />" : lbedit.Text;

        LinkButton lbdelete = (LinkButton)row.Cells[0].Controls[2];
        lbdelete.Text = lbdelete.Text == "Delete" ? "<img title=\"Delete\" class=\"icon\" src=\"Images/delete.png\" />" : lbdelete.Text;

        LinkButton lbselect = (LinkButton)row.Cells[0].Controls[4];
        lbselect.Text = lbselect.Text == "Select" ? "<img title=\"Select\" class=\"icon\" src=\"Images/accept.png\" />" : lbselect.Text;
    }
}

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

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

发布评论

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

评论(1

清音悠歌 2025-01-09 03:59:29

您可以将“OnClientClick”添加到请求确认的链接按钮。然后使用“OnClick”执行 C# 函数。希望有帮助。

<asp:LinkButton ID="Deletebutton" runat="server" CausesValidation="False" OnClientClick='return confirm("Are you sure you want to remove this?");'  OnClick="DeleteBrand">

You can add an "OnClientClick" to an linkbutton asking for confirmation. And performing an C# function afterwards using "OnClick". Hope it helps.

<asp:LinkButton ID="Deletebutton" runat="server" CausesValidation="False" OnClientClick='return confirm("Are you sure you want to remove this?");'  OnClick="DeleteBrand">

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