I’m using a gridview to display large amounts of data.
The data source is stored in session, so that I can page/sort the gridview without having to take additional trips to the SQL server.
Is there a better way to page/sort the grid without having to store the data in session?
I think it all depends on the amount of data you are working with. If you are working with a few hundred rows, I would suggest looking at the jQuery plugin DataTables. From your code point of view, you make a regular table, and then in the document.Ready event you apply the DataTables script. It has paging, sorting, and filtering. It’s pretty powerful.
If you are working with a thousand or more rows, I would suggest doing paging and sorting server side. In this case, when the user pages, you go to the database again and only return the number of rows they are viewing at any given time. So if you only show 50 records on a page, your query should only return 50 records. This way is a bit more tricky, but will be should be faster for the user, and also doesn’t run the risk of reaching the max page size.