【问题标题】:Replacing an ImageButton with a styled icon用样式图标替换 ImageButton
【发布时间】:2015-08-07 13:34:42
【问题描述】:

我需要用 CSS 样式的图标替换 GridView ItemTemplate 中的 ImageButton

通常我会通过将 ImageButton 替换为隐藏按钮来执行此操作,然后调用一些 JQuery 来单击隐藏按钮。像这样的:

<a class="btn" href="#" onclick="Utils.ClickButton('<%= btnTest.ClientID %>');"><i class="icon">&nbsp;</i>Download to Excel</a>
                <asp:Button ID="btnTest" CssClass="btn" ToolTip="Download to Excel" runat="server" />

但是,这似乎不适用于具有将网格置于编辑模式的命令参数的 ImageButton。如果我执行上述操作,我会收到一个运行时错误,提示找不到 btnTest。

所以我需要的是:

<asp:ImageButton ID="btnDelete" CommandArgument='<%#Eval("ID")%>' ToolTip="Delete" runat="server" CommandName="Delete"
                                ImageUrl="/images/delete.png" />

看起来像这样:

<a class="btn" href="#" onclick="Utils.ClickButton('<%= btnTest.ClientID %>');"><i class="icon">&nbsp;</i></a>

【问题讨论】:

    标签: jquery css asp.net gridview


    【解决方案1】:

    您可以使用 LinkBut​​ton 实现此目的

    <asp:LinkButton runat="server" CommandName="Delete" CommandArgument='<%#Eval("ID")%>' CssClass="btn"> <i class="icon">&nbsp;</i> </asp:LinkButton>

    您可以在 GridView 的 RowCommand 事件中处理 LinkBut​​ton 点击​​

    protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {
           //Handle Delete Command
        }                     
    }
    

    【讨论】:

    • 我不推荐使用 Eval,here 是为什么!
    • Eval 已被淘汰 :-)
    猜你喜欢
    • 2018-03-03
    • 2011-03-08
    • 2018-03-06
    • 2017-03-13
    • 1970-01-01
    • 2017-05-11
    • 2016-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多