The DataGrid Web control includes a bevy of common features, such as paging, sorting, and row-by-row editing of the DataGrid's
underlying data. We've discussed how to accomplish these tasks in previous installments of the
An Extensive Examination of the DataGrid Web Control article series, first looking
at creating a sortable DataGrid in Part 4. Unfortunately the DataGrid's built-in sorting
only allows for uni-directional sorting. That is, when creating the DataGrid you must decide on a column-by-column basis
if the data will be sorted in ascending or descending order.
While it's impressive the ease with which uni-directional sorting can be added to a DataGrid, ideally we'd like to offer
bi-directional sorting. There are a couple of techniques that can be used to accomplish this end, one of which was discussed
in Part 12 of this article series. Specifically, Part 12 showed how to dynamically
adjust each DataGrid column's SortExpression property to toggle ascending or descending sorting. One downside
of this approach, as Part 12 noted, was that you needed to hard-code in sortable column, mapping the SortExpression
to the appropriate DataGridColumns index. This downside of this approach, then, is that it would need to be customized
for each page that you wanted to use a bi-directional sortable DataGrid.
In this 18th part of the An Extensive Examination of the DataGrid Web Control article series we'll look at an alternative
approach to implementing bi-directional sorting, one that doesn't require any hard-coded mapping and therefore can easily
be reused. We'll also look at a simple method that will enhance the appearance of our bi-directional sortable DataGrid,
adding little up and down arrows on the column header that the grid's data is sorted by. Read on to learn more!
(If you are unfamiliar with creating a sortable DataGrid, please take a moment to first read Part 4
of this article series before continuing; if you have never created a bi-directional sortable DataGrid, be sure to
read Part 12 before tackling this part.)
Read More >