5,446,542 members and growing! (18,177 online)
Email Password   helpLost your password?
Web Development » ASP.NET Controls » Grid Controls     Intermediate License: The Code Project Open License (CPOL)

Improving the GridView sorting capabilities with Google Analytics features

By Luis Ramirez

Improve the column sorting of the ASP.NET GridView to give the user a better visual experience. Highlight the column selected for sorting and include an image to indicate whether the sorting order is ascending or descending.
CSS, HTML, C#, ASP.NET, Dev

Posted: 12 May 2008
Updated: 12 May 2008
Views: 5,701
Bookmarked: 11 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
4 votes for this Article.
Popularity: 1.66 Rating: 2.75 out of 5
1 vote, 25.0%
1
0 votes, 0.0%
2
2 votes, 50.0%
3
1 vote, 25.0%
4
0 votes, 0.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Google Analytics ASP.NET Grid Column sorting

Visit http://www.sqlnetframework.com/Articles/GoogleAnalyticsAspNetGridSortColumn.aspx to see the original article and download the source code.
Last update: May 12, 2008
Author: Luis Ramirez.
Author's website: http://www.sqlnetframework.com

In the following article you will learn how you can improve the column sorting of the ASP.NET GridView to give the user a better visual experience. The Google Analytics ASP.NET Grid column sorting will indicates the sorting order direction (ascending or descending) and will highlight the GridView column used to make the sorting.

Google Analytics ASP.NET Grid column sorting

Google Analytics ASP.NET Grid Serie

The Google Analytics ASP.NET Grid Serie will show you how to create an ASP.NET Grid that recreates the appearance and behavior of the Grid displayed in the Google Analytics web site.

Improving ASP.NET GridView sorting capabilities

Many of us have used the ASP.NET GridView webcontrol to display information. One of the features most used of the GridView webcontrol is GridView sorting. The GridView sorting allow us to sort the information in the GridView using the column name displayed at the top of the GridView.

GridView column sort

Default GridView sorting capability

If you are working with the GridView webcontrol and you want to enable the GridView sorting capability you need to set to true the GridView’s AllowSorting property.

GridView allow sorting

Now that the GridView sorting feature is enabled the GridView webcontrol will display a link for each column header. When the user clicks the link in the column header the information displayed in the GridView will be sortered using the SortExpression defined in the GridView column.

GridView sort expression

Default GridView sorting direction

The first time that you click a column header the GridView sorting direction is ascending (A, B, C, etc), the second time that you click the same column header the GridView sorting direction changes to descending (C, B, A, etc).

Implementing GridView sorting like in Google Analytics

The Google Analytics Grid has features that seem interesting to be implemented in any ASP.NET project using the GridView to display and sort information. The first GridView sorting feature that we will implement will be to display an image to notify the user the GridView sorting direction: ascending or descending. The second feature will be to highlight the header and each row of the selected GridView column to make easy for the user to know which GridView column was used for sorting.

GridView sort order arrow

Using an image to display the GridView sorting direction

When the user clicks a GridView column header for sorting an image will be displayed in the GridView column header to notify the user the GridView sorting direction. To display the image we are going to check whether the current column header was clicked for sorting, if so, we are going to check the GridView sorting direction: ascending or descending. Depending whether the GridView column header was clicked or not we are going to select the css-style to apply.

GridView sort order arrow

Highlighting the GridView sorting column

When the user clicks a GridView column header for sorting all the GridView column will be highlighted, including the column header and the rows. To highlight a row item we will check whether the row item is under the GridView column header clicked for sorting.

GridView sorted column

How to use the new GridView sorting capabilities in my ASP.NET web projects?

You only need to add a GoogleAnalyticsGridViewColumnSortField within the Columns collection of the GridView webcontrol.

GridView colum sort field

The SortedColumnCssClass and ColumnCssClass properties specifies the css-style to be applied to a GridView column when the GridView column is clicked for sorting and when the GridView column is at a normal state without being selected, respectively. You need to specify a value at least to the SortedColumnCssClass property. Finally you need to create a style sheet to create the style items used for the rendering of the GridView.

GridView colum sort css properties

Style used for the sorted GridView column

If you assign the value "googleAnalyticsSortedColumn" to the SortedColumnCssClass property of the GoogleAnalyticsGridViewColumnSortField class then you need to create the style items displayed below.

GridView sorted colum header css

Style used for the normal GridView column

If you assign the value "googleAnalyticsColumn" to the ColumnCssClass property of the GoogleAnalyticsGridViewColumnSortField class then you need to create the style items displayed below.

GridView colum header css

Conclusion

Now with just including the GoogleAnalyticsGridViewColumnSortField item to the Columns collection of the GridView webcontrol you can have a better sorting functionality for the GridView. To modify the GridView appearance you only need to edit the css-style sheet file associated with the GridView webcontrol. Download the Google Analytics ASP.NET Grid Sort Column code to see how easy is to use the new GridView sorting features.

Google Analytics ASP.NET Grid column sorting

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Luis Ramirez


Luis Ramirez is creator and owner of http://www.sqlnetframework.com. The SqlNetFramework is a compelling alternative to the Microsoft Data Access Application Block. Luis Ramirez is a Microsoft Certified Professional specialized in .NET development. If you want to contact him to work in your projects or for any other inquiry that you have write him to lramirez [at] sqlnetframework.com.
Occupation: Software Developer (Senior)
Company: www.sqlnetframework.com
Location: Mexico Mexico

Other popular ASP.NET Controls articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 4 of 4 (Total in Forum: 4) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralWhat is the A for in .googleAnalyticsSortedColumnHeaderDescending AmemberSeaWater4:42 31 Jul '08  
AnswerRe: What is the A for in .googleAnalyticsSortedColumnHeaderDescending AmemberLuis Ramirez7:54 31 Jul '08  
GeneralGoodmembersrinath g nath19:49 12 May '08  
GeneralRe: GoodmemberLuis Ramirez8:44 13 May '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 12 May 2008
Editor:
Copyright 2008 by Luis Ramirez
Everything else Copyright © CodeProject, 1999-2008
Web18 | Advertise on the Code Project