在TemplateField中用Headertemplate替换HeaderText [英] Replacing HeaderText with Headertemplate in TemplateField
问题描述
我有一个带有templatefield列的gridview. TemplateFields是这样的:
I have a gridview with templatefield columns. The TemplateFields are something like this:
<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并添加了以下内容:
I have to add a custom attribute for to the header of this columns so I removed HeaderText and added the following:
<Headertemplate>
<asp:Label ID="lblTitleHeading" runat="server" Text="Title" data-custom="tbl-th_title_heading"></asp:Label>
</Headertemplate>
我的问题是,当我这样做时,它将破坏该列的排序,并且我无法再单击标题以对其进行排序,我尝试将更改为,但是却无济于事. 谢谢您的回答.
My problem is when I do this, it will break the sorting of that column and I cannot click on the header to sort it anymore, I tried changing the to but that didn't do anything. I would appreciate your answers.
推荐答案
好吧,我刚刚找到了解决方法,我只需要将Label更改为LinkButton并添加CommandName ="Sort"和CommandArgument ="name"(或任何SortExpression)
Ok I just found out how to do this, I just needed to change the Label to LinkButton and add CommandName="Sort" and CommandArgument="name" (or any SortExpression)
<Headertemplate>
<asp:LinkButton ID="lblTitleHeading" runat="server" Text="Title" data-custom="tbl-th_title_heading" CommandName="Sort" CommandArgument="name"></asp:LinkButton>
这篇关于在TemplateField中用Headertemplate替换HeaderText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!