Sorting Columns

It would be nice if your table could sort its data when you click a column within the table. It would be even better if the data could toggle between sorting in ascending order and sorting in descending order when you click the column header multiple times. You can accomplish this goal, but you'll need to write some code to make it happen.

No sorting can occur in the DataGrid control unless you handle two issues:

  • The control's AllowSorting property must be set to True.

  • Each column for which you want to allow sorting must have its SortExpression property set to reflect the expression you'd like to use for sorting when that column is selected.

You handled both of these issues when you created the DataGrid control earlier in the chapter. ...

Get ASP.NET Developer's JumpStart now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.