GeekArticles
Database
SQL ServerExtending the GridView to Include Sort Arrows
Author: aspnet.4guysfromrolla.com |
Published: 23rd Jan 2008 |
Visited: 115 times |
Add CommentFiled in: SQL Server
Before ASP.NET version 2.0 was released, I wrote
a book and dozens of articles on the DataGrid control, which was the most functional data Web control in the
ASP.NET 1.x toolbox. While the DataGrid still exists in ASP.NET 2.0, the GridView control serves as
a much more functional and feature-rich choice. The GridView can be bound to data source controls like the SqlDataSource and ObjectDataSource, and
paging, sorting, editing, and deleting can be implemented without having to write a single line of code.
While the DataGrid (and GridView) offer built-in sorting support, there is no visual feedback as to what column the data is sorted by.
In Part 18 of the An
Extensive Examination of the DataGrid Web Control article series, I showed how to dynamically update a sortable DataGrid's header columns so that
an up or down arrow image would appear next to the sorted column name depending on whether the column was sorted ascendingly or descendingly (view
a live demo). This was accomplished by programmatically looping through the DataGrid's
Columns collection and adding the up or down arrow image to column whose SortExpression value matched the DataGrid's
SortExpression.
I recently needed to implement this functionality in a GridView control. Rather than adding this code to an ASP.NET page, like I did with the
DataGrid demo, I decided to instead create a custom Web server control that extended the GridView control, adding the necessary functionality.
In this article we will look at the steps for building such a custom control as well as how to use the control in an ASP.NET page. The custom
control's complete source code and a demo application are available for download at the end of this article. Read on to learn more!
Read More >
Read Article Sponsored Links
Related Articles