ComponentOne GridView for ASP.NET WebForms
Working with GridView for ASP.NET Web Forms / Sorting
In This Topic
    Sorting
    In This Topic

    The C1GridView control provides built-in sorting functionality without requiring any coding. You can further customize the sort functionality of the C1GridView control by using custom SortExpression property values for columns as well as by using the Sorting and Sorted events.

    You can enable the default sorting behavior in the C1GridView control by setting its AllowSorting property to True. When AllowSorting is True, the C1GridView control renders a LinkButton control in the column headers and implicitly sets the SortExpression property of each column to the name of the data field to which it is bound. For example, if the grid contains a column that displays the City column of the Employees table in the Northwind sample database, the SortExpression of that column will be set to City. You can determine or set the sort direction with the SortDirection property (Ascending, Descending, or None).

    At run time, users can click the LinkButton control in a column heading to sort by that column. Clicking the link causes the page to perform a postback and raises the C1GridView control's Sorting event. After the query has executed, the grid's Sorted event is raised. Finally, the data source control rebinds the C1GridView control to the results of the resorted query. When a column is sorted, the column header will display a sort indicator at run time (an arrow icon) indicating the direction of the sort.

    In the following image, the Skaters column was sorted:

    Note that if the data source control does not support sorting and a sorting operation is performed in the C1GridView control, the C1GridView control throws the NotSupportedException exception. You can catch this exception in a handler for the Sorting event and check the data source to determine whether sorting is supported, or by using your own sorting logic.

    You can use AJAX to update the grid when the user sorts a column at run time by setting the Action property. For an example, see Sorting Columns.

    See Also