Letting the visitor sort the grid
Sorting by column heading is a small feature that makes a long list far more usable.
Turn it on
Markup
<asp:GridView id="productsGrid" runat="server"
DataSourceID="productsSource"
AllowSorting="true" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Name"
HeaderText="Product" SortExpression="Name" />
</Columns>
</asp:GridView>What has to be true
- Each sortable column needs a sort expression that names a real column in the query.
- The data source must be able to sort, which the data source control handles for you.
Sort before you page. When a grid both sorts and pages, the sort must be applied to the whole result, not just the page in view, or the second page will be out of order.
Paging is the natural companion, in paging through many rows.