【问题标题】:Replacing HeaderText with Headertemplate in TemplateField在 TemplateField 中用 Headertemplate 替换 HeaderText
【发布时间】:2014-07-07 21:03:44
【问题描述】:

我有一个带有模板字段列的网格视图。 TemplateFields 是这样的:

<asp:TemplateField HeaderText="Title" SortExpression="name" meta:resourcekey="BoundFieldResource1">
                                <ItemTemplate>
                                    <asp:Label ID="lblTitle" runat="server" 
                                        Text='<%# Bind("Name") %>' 
                                        meta:resourcekey="BoundFieldResource1"></asp:Label>
                                </ItemTemplate>

我必须为此列的标题添加自定义属性,因此我删除了 HeaderText 并添加了以下内容:

<Headertemplate>
         <asp:Label ID="lblTitleHeading" runat="server" Text="Title" data-custom="tbl-th_title_heading"></asp:Label>
</Headertemplate>

我的问题是,当我这样做时,它会破坏该列的排序,我无法单击标题对其进行排序,我尝试将其更改为但没有做任何事情。 我会很感激你的回答。

【问题讨论】:

    标签: sorting webforms custom-attributes aspxgridview templatefield


    【解决方案1】:

    好的,我刚刚知道如何执行此操作,我只需将 Label 更改为 LinkBut​​ton 并添加 CommandName="Sort" 和 CommandArgument="name"(或任何 SortExpression)

    <Headertemplate>
         <asp:LinkButton ID="lblTitleHeading" runat="server" Text="Title" data-custom="tbl-th_title_heading" CommandName="Sort" CommandArgument="name"></asp:LinkButton>
    

    【讨论】:

      猜你喜欢
      • 2019-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-21
      • 1970-01-01
      • 2020-02-20
      相关资源
      最近更新 更多