Geeks With Blogs

  • azamsharp The WWDC app says that there are new videos but there is nothing under videos!!! about 683 days ago
  • azamsharp Can I post my opinion on iOS 7 Beta or is it under NDA or something? about 683 days ago
  • azamsharp iOS 7 BETA installed successfully! about 683 days ago
  • azamsharp iOS 7 BETA installed! Now restoring! I am on NET10 which uses AT&T network. Hopefully 3G will still work! Lets c.. about 683 days ago
  • azamsharp The missing of button borders in Xcode 5 makes it hard to determine the clickable area. about 683 days ago
  • azamsharp I might wait for iOS to be released before I can put it on my device! Don't want a bricked or unstable device! about 683 days ago
  • azamsharp Android has many features that no one uses, number of versions that no one upgrades to and thousands of apps that no one pays for. about 683 days ago
  • azamsharp Maybe it is just me but the new iOS 7 UI looks like Windows Phone 8 UI! #maybeIamCrazy about 684 days ago
  • azamsharp Anyone using H20 network upgraded to iOS 7 BETA Keep me updated if you face any problems. about 684 days ago
  • azamsharp @merowing_ You already downloaded it! I cannot even load the developer's website! :( about 684 days ago

AzamSharp Some day I will know everything. I hope that day never comes.

GridView control offers a cool property "EnableSortingAndPagingCallbacks" which enables the user to perform paging and sorting without any postbacks. Although the feature is pretty neat but it has some BIG limitations. First of all you can only use the DataSourceID property of the GridView to assign the data source. This rules out DataSets, DataTables and Custom Collections (My Favourite). So, only thing left for you to use is SqlDataSource and ObjectDataSource controls. When using SqlDataSource you basically have to do nothing simply assign the DataSourceID of the GridView to SqlDataSource control and that's it and also EnableSortingAndPagingCallbacks = true.

When using ObjectDataSource things get's little tricky. One easy way around is to return a DataView back to the client. The GetProductsUsingDataView can be used as the SelectMethod for the ObjectDataSource control.


public DataView GetProductsUsingDataView(string sortExpression)


string connectionString = @"Server=localhost;Database=Northwind;Trusted_Connection=true";

SqlConnection myConnection = new SqlConnection(connectionString);

SqlCommand myCommand = new SqlCommand("SELECT ProductID, ProductName FROM Products", myConnection);

SqlDataAdapter ad = new SqlDataAdapter(myCommand);

DataSet ds = new DataSet();


DataView dv = ds.Tables[0].DefaultView;

dv.Sort = sortExpression;

return dv;


Another method is to keep track of the ascending and descending using the Session variable and alter the SQL query using the ORDER BY clause to get the ordered result. A better approach is to make use of the IComparer interface and implement a Generic IComparer to handle the sorting. 

Stephane Schwartz wrote an excellent article about implementing the Generic Sort Method. You can check out the article at the following link:

Posted on Wednesday, September 20, 2006 1:39 PM | Back to top

Comments on this post: GridView Property EnableSortingAndPagingCallbacks

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Mohammad Azam | Powered by: | Join free