How to sort template field by clickin gridview column header

Posted by Oswaldlily under ASP.NET on 7/29/2011 | Points: 10 | Views : 33723 | Status : [Member] | Replies : 1
hey this is my column in my gridview ..i need to use sorting.
condition 1) i dont want to write sql query in codebehind.
i can write in storedprocedure and call in codebehind

then i need to know whether v can sort without any query....
since i dint use boundfield feelin lot of confusion in sorting.
so plz help me

<asp:TemplateField HeaderText="Employeename" SortExpression="Employeename" >
<HeaderTemplate>
<asp:LinkButton ID="lnkgroup" runat="server" CommandArgument="Employeename" CommandName="Sort"
ForeColor="white" Text="<%$ Resources:DefaultResource, Employeename %>"
></asp:LinkButton>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lab2" runat="server"
Text='<%# Eval("Employeename") %>' Width="300px"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TxtId" runat="server"
Width="300px"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>




Responses

Posted by: SheoNarayan on: 7/29/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Hi Vijila,

Its not as hard as it looks like, read this article http://www.dotnetfunda.com/articles/article1372-how-to-sort-the-gridview-data-.aspx, in this for every sorting a new database query is not executing. Sorting is being done at the page level using the DataView.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response