ASP.NET GridView Tutorial
Lesson 208 of 301 · Sorting a gridview that uses sqldatasource control – Part 44 · Database
Sorting a gridview that uses sqldatasource control – Part 44
Link for csharp, asp.net, ado.net, dotnet basics and sql server video tutorial playlists
http://www.youtube.com/user/kudvenkat/playlists
Link for text version of this video
http://csharp-video-tutorials.blogspot.com/2013/04/sorting-gridview-that-uses.html
In this video we will discuss about sorting a gridview control that use sqldatasource control. We will discuss about sorting in both ascending and descending order.
We will be using tblEmployee table for this demo. Please refer to Part 13 using the link below, if you need the sql script to create and populate these tables.
http://csharp-video-tutorials.blogspot.com/2013/02/deleting-data-from-gridview-using.html
Step 1: Drag and drop a gridview and a sqldatasource control on webform1.aspx
Step 2: Configure SqlDataSource1 control to retrieve data from tblEmployee table.
Step 3: Associate GridView1, with SqlDataSource1 control and make sure to select “Enable Sorting” checkbox.
That’s it we are done. Run the application. Click on any column to sort the data. Notice that, when you click once on the column header, the data will be sorted in ascending order, and if you click again the data will be sorted in descending order. A gridview that is sortable in both directions is called as bi-directional sortable gridview.
Points to remember
1. When sorting is enabled, AllowSorting attribute of GridView1 is set to true.
AllowSorting=”True”
2. If you don’t want to sort on a specific column, remove SortExpression attribute from that column