Second Stanza

February 18, 2008

Paged and Sorted ASP.NET Data Grids

Filed under: .NET Examples, ASP.NET — Tags: , , — dfbaskin @ 7:35 pm

The ASP.NET class, ObjectDataSource, performs most of the dirty work of coordinating activity between a data source and a data grid presented on an web page, including handling sorting and paging issues.

When the data source is SQL Server, it is, of course, more efficient to return only the subset of data to be displayed, rather than returning the entire data set to the ASP.NET application and extracting the subset there. One technique to handle this scenario, is to make use of a temporary table containing the index to the records in the order they are to be displayed to the user. Then a query and a join can be used to extract the subset of records for the page of records currently displayed within the grid.

The source code below demonstrates this technique using the AdventureWorks sample database included with SQL Server 2005. This code includes a data grid using the GridView web control and one using Infragistic’s UltraWebGrid control. Note that you can sort by any of the column headings and page through the sorted list without coding additional sorting or paging functionality.

Download / View Source Code
(View requires Microsoft Silverlight 1.0 and Internet Explorer)

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: