Click here to Skip to main content
15,890,946 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi ,

I am having gridview as below html tag
ASP.NET
<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.
Posted
Updated 4-Jul-13 21:06pm
v2

1 solution

You could try something like below (this is a sample code):

Changed this :

XML
<asp:TemplateField SortExpression="Category">
   <HeaderTemplate>Category</HeaderTemplate>
   <ItemTemplate>A value</ItemTemplate>
</asp:TemplateField>


To This :

XML
<asp:TemplateField HeaderText="Category" SortExpression="Category">
   <ItemTemplate>A value</ItemTemplate>
</asp:TemplateField>



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.
 
Share this answer
 
Comments
Mithun P 5-Jul-13 4:42am    
Hi Thanks for giving suggestion,ya it work fine if i don't use table inside the header and item template but my design is such that i have to use the table inside header and item template.. When i don't use table inside item template it works fine but i want it to work when i am using table inside header and item template. Hope u understood my problem
Sampath Lokuge 5-Jul-13 5:27am    
@Mithun As a try just remove tables and use only div's for create your requirement.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900