.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

How to sort template field by clickin gridview column header

Posted By: oswaldlily     Posted Date: July 29, 2011    Points:5   Category :ASP.Net
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
Author: Dhiraj Ranka             
Posted Date: July 29, 2011     Points: 20   

Hi,

Simply make the grid view sortable (AllowSorting="True" in the GridView control). And specify the SortExpression="<BoundFieldName>".

More if you want to handle the sorting event then you can use OnSorting="gridView_Sorting" this in grid view control and put logic of yours in the code behind.

That's it.

Hope this helps.

Thanks & Regards,
Dhiraj Ranka
http://www.twitter.com/dhirajranka | http://www.dhirajranka.com
Author: viji             
Posted Date: July 29, 2011     Points: 20   

I need to sort both in ascendinhg and descending..
so can u suggest me some code?

Author: Dhiraj Ranka             
Posted Date: July 29, 2011     Points: 20   
Author: Gowthammanju             
Posted Date: July 29, 2011     Points: 20   

TRY these link as

http://www.asp.net/data-access/tutorials/using-templatefields-in-the-gridview-control-cs

which is step by step procedure

Thanks & Regards,
GowthamManju
Chennai



Mark if the answer is true
Author: Gowthammanju             
Posted Date: July 29, 2011     Points: 20   

try these as

first place the

<asp:TemplateField>
</asp:TemplateField


then

<ItemTemplate>
<asp:Label ID="label1" Runat="server" />
</ItemTemplate>


inside a grid view

Thanks & Regards,
GowthamManju
Chennai



Mark if the answer is true
Author: Gowthammanju             
Posted Date: July 29, 2011     Points: 20   

sample coding for grid view here it is as

<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:Image ID="Image1" runat="server" />&nbsp;
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</EditItemTemplate>
<ItemTemplate>
&nbsp;
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If CType(GridView1.Rows(GridView1.EditIndex).FindControl("FileUpload1"), FileUpload).HasFile Then
Dim extension As String = System.IO.Path.GetExtension(CType(GridView1.Rows(GridView1.EditIndex).FindControl("FileUpload1"), FileUpload).PostedFile.FileName)
Select Case extension.ToLower()
Case ".jpg", ".jpeg", ".gif", ".bmp"
'do something
End Select
End If
End Sub



try these way

Thanks & Regards,
GowthamManju
Chennai



Mark if the answer is true
Author: Gowthammanju             
Posted Date: July 29, 2011     Points: 20   

try these u will find solution by steps as


http://authors.aspalliance.com/aspxtreme/webforms/controls/addingtemplatefieldstogridview.aspx

Thanks & Regards,
GowthamManju
Chennai



Mark if the answer is true
Author: Sasi Prabhu             
Posted Date: July 29, 2011     Points: 20   

Refer :

http://geekswithblogs.net/AzamSharp/archive/2006/04/27/76612.aspx

http://www.dotnetspider.com/resources/1249-Grid-View-Paging-Sorting.aspx

http://www.netomatix.com/development/GridViewSorting.aspx

Thanks & Regards,
Sasi Prabhu.


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend