Replacing HeaderText with Headertemplate in TemplateField

二次信任 提交于 2019-12-10 17:14:49

问题


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>

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.


回答1:


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>



来源:https://stackoverflow.com/questions/23745611/replacing-headertext-with-headertemplate-in-templatefield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!