Sorting a Grid of Data in ASP.NET MVC

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Last weeks article, http://www.4guysfromrolla.com/articles/121510-1.aspx Displaying a Grid of Data in ASP.NET MVC , showed, step-by-step, how to display a
grid of data in an http://www.asp.net/mvc ASP.NET MVC application. Last weeks article started with creating a new ASP.NET MVC application in Visual Studio,
then added the Northwind database to the project and showed how to use Microsofts Linq-to-SQL tool to access data from the database. The article then looked at creating
a Controller and View for displaying a list of product information (the Model).

This article builds on the demo application created in <i>Displaying a Grid of Data in ASP.NET MVC</i>, enhancing the grid to include bi-directional sorting.
If you come from an ASP.NET WebForms background, you know that the GridView control makes implementing sorting as easy as ticking a checkbox. Unfortunately, implementing
sorting in ASP.NET MVC involves a bit more work than simply checking a checkbox, but the quantity of work isnt significantly greater and with ASP.NET MVC we have
more control over the grid and sorting interfaces layout and markup, as well as the mechanism through which sorting is implemented. With the GridView control, sorting
is handled through form postbacks with the sorting parameters - what column to sort by and whether to sort in ascending or descending order - being submitted as hidden
form fields. In this article well use querystring parameters to indicate the sorting parameters, which means a particular sort order can be indexed by search engines,
bookmarked, emailed to a colleague, and so on - things that are not possible with the GridViews built-in sorting capabilities.

Like with its predecessor, this article offers step-by-step instructions and includes a complete, working demo available for download at the end of the article.
Read on to learn more!

http://www.4guysfromrolla.com/articles/122210-1.aspx" class="readmore Read More >

View the full article
 
Back
Top