In a previous article I had written on Dynamic Column Sorting and Paging in ASP.NET, I demonstrated one of nine ways one could page and bi-directionally sort a DataGrid. I opted for the old hidden field method. At any rate, this method, among the eight others works fine, and it all depends on how you want to approach this based on any given factors in your app. Having said that, the problems we'll be discussing here lay not with either the paging or sorting aspects of it, but rather in implementing the most efficient manner in retrieving data and presenting it to the client.
No one wants to bog down a server with unnecessary network traffic by displaying hundreds or even thousands of rows or data, nor in furthermore weighing down server resources by creating any unnecessary memory demanding objects, when you can easily conserve resources and time by utilizing more lightweight data objects to display data with.
As you may or may not realize, there are numerous ways to bind a DataGrid. The most common way is the typical DataAdapter/DataSet combo. Although, this method has its proper setting and time to be used, you'll need to realize that aside from data modification or management, employing this strategy will prove in hindering performance, as the DataSet is definitely slower that the lightning fast read-only, forward-only DataReader. Some performance statistics worth mentioning can be found here - Performance Comparison: Data Access Techniques.
For some real good further reading can be found here Why I Don't Use DataSets in My ASP.NET Applications and More On Why I Don't Use DataSets in My ASP.NET Applications.
Now, the Datareader is forward-only right? Hmm, but what about paging and sorting? Can we natively implement a DataReader to provide paging and sorting as one would typically with a DataSet? The answer unfortunately is no, and if you try doing this you receive this error message:
It is after all a foward-only cursor type object. However, there are ways around this and in this article I will demonstrate how you could not only use the DataReader to bind a DataGrid, but cache it, page it and persistently and bi-directionally sort it!