Data Access has been discontinued. Please refer to this page for more information.

Ordering Data

This topic demonstrates how to use the OpenAccessLinqDataSource control to order the retrieved records.

Ordering the Retrieved Records

The OrderBy property of OpenAccessLinqDataSource allows you to specify the columns you would like to order by. The following example shows the markup for part of an ASP.NET Web page that contains an instance of OpenAccessLinqDataSource. The control is configured to enable the user to display all columns from a table named Categories. The returned records will be ordered by the CategoryID and CategoryName columns:

<telerik:OpenAccessLinqDataSource
    ID="OpenAccessLinqDataSourceCategory"
    runat="server" EntityTypeName=""
    ContextTypeName="SofiaCarRental.Model.FluentModel"
    ResourceSetName="Categories" OrderBy="CategoryID, CategoryName desc">
</telerik:OpenAccessLinqDataSource>

If you do not explicitly specify desc after the name of a property in the OrderBy clause, the returned results will be in ascending order.

How to: Enable/Disable Automatic Sorting in an OpenAccessLinqDataSourceControl

Some data-bound controls (e.g. RadGrid control) let users sort the data without requiring any code. The OpenAccessLinqDataSource control provides built-in support for sorting. The OpenAccessLinqDataSource control exposes the AutoSort property. The AutoSort property indicates whether the OpenAccessLinqDataSource control supports sorting the data at runtime. The default value for this property is True. If you want to disable the sorting functionality at runtime, you need to change the AutoSort property to False:

  1. Open your page in design mode and select the OpenAccessLinqDataSource control.
  2. Press F4 to open the Properties pane. Modify the AutoSort property. True to enable the sorting functionality; otherwise, False.
<telerik:OpenAccessLinqDataSource
    ID="OpenAccessLinqDataSourceCategory"
    runat="server" EntityTypeName=""
    ContextTypeName="SofiaCarRental.Model.FluentModel"
    AutoSort="False">
</telerik:OpenAccessLinqDataSource>