Sorting Columns

The DataGrid control does not actually sort rows, but it provides good support for sorting as long as the sorting capabilities of the underlying data source are adequate. The data source is always responsible for returning a sorted set of records based on the sort expression selected by the user through the DataGrid control’s user interface. The built-in sorting mechanism is triggered by setting the AllowSorting property to true.

<asp:datagrid id="grid" runat="server" 
    ⋮
    AllowSorting="True"
    OnSortCommand="SortCommand">

When AllowSorting is set to true, the DataGrid control offers a link button for rendering the column caption. When users click one of these sortable columns, the SortCommand event is fired. In the ...

Get Building Web Solutions with ASP.NET and ADO.NET 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.