在Gridview中排序如果templatefield有表,则不起作用
我的网格视图如下html标签
Hi ,
I am having gridview as below html tag
<asp:gridview id="grdView" runat="server" onsorting="grdView_Sorting" allowsorting="true">
<columns>
<asp:TemplateField SortExpression="CategoryCode">
<HeaderTemplate>
<table width="730px" border="1">
<tr>
<td>
---- I have some header names inside this td's
</td>
</tr>
</table>
</HeaderTemplate>
<itemtemplate>
<table border="0" class="displaygrid" width="730px">
<tr>
<td>
<div>
<%# Eval("Description")%>
</div>
</td>
<td>
<div>
<%# Eval("CategoryCode")%>
</div>
</td>
</tr>
</table>
</itemtemplate></columns>
如果我有设计,排序不会以这种方式运作,请任何人都可以帮助我。
Sorting is not working in this way if i have designed ,please can anyone help me.
您可以尝试下面的内容(这是示例代码):
改变了这个:
You could try something like below (this is a sample code):
Changed this :
<asp:TemplateField SortExpression="Category">
<HeaderTemplate>Category</HeaderTemplate>
<ItemTemplate>A value</ItemTemplate>
</asp:TemplateField>
至此:
To This :
<asp:TemplateField HeaderText="Category" SortExpression="Category">
<ItemTemplate>A value</ItemTemplate>
</asp:TemplateField>
删除了 HeaderTemplate 并添加了 HeaderText TemplateField 。
欲了解更多信息: http://stackoverflow.com/questions/1597977/gridview-sorting-with-custom-template-fields [ ^ ]
关于如何使用网格视图处理模板字段的完整文章:
http://www.asp.net/web-forms/tutorials/data-access/custom-格式化/使用templatefields-in-the gridview-control-cs [ ^ ]
我希望这会对你有所帮助。
Removed the HeaderTemplate and added the HeaderText in the TemplateField.
For more info : http://stackoverflow.com/questions/1597977/gridview-sorting-with-custom-template-fields[^]
Complete article about How to handle Template fields with Grid view :
http://www.asp.net/web-forms/tutorials/data-access/custom-formatting/using-templatefields-in-the-gridview-control-cs[^]
I hope this will help to you.