asp.net.ph

Skip Navigation Links

Adding Sorting to a GridView Control

Controls You Can Use on Web Forms   ASP.NET Data Controls   GridView Control


The GridView control provides a default sorting functionality without requiring any coding. If the default sort behavior is not adequate for the need, though, the GridView provides for customization of the default sort functionality.

Specifying Default Sorting

With the default setting, all columns in the grid are sortable. The headers for all columns are automatically rendered as LinkButton controls, that users can click to arrange the ordering of the grid contents by that column.

To specify default sorting

  1. Set the GridView control’s AllowSorting property.
    <asp:GridView id="myGrid" runat="server"
       datasourceid="customers"
       allowsorting=true
       ...
    >

    or simply

    <asp:GridView id="myGrid" runat="server"
       datasourceid="customers"
       allowsorting
       ...
    >
Run Sample | View Source



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note