Sorting Data
You can sort the rows rendered by a GridView
control by enabling the AllowSorting
property. For example, the page in Listing 11.5 illustrates how you can sort the contents of the Movies database table.
Listing 11.5. SortGrid.aspx
When AllowSorting
has the value True
, column headers render as links. When you click a column header, you can sort the rows contained in the GridView
in the order of the selected column.
Note
When using explicitly specified fields with a GridView
, such as BoundFields
, you need to specify values for the fields’ SortExpression
properties. Otherwise, nothing happens when you click a header.
The GridView ...
Get ASP.NET 4 Unleashed 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.