This documentation is archived and is not being maintained.

LinqDataSource.AutoSort Property

Gets or sets a value that indicates whether the LinqDataSource control supports sorting the data at run time.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

public bool AutoSort { get; set; }
<asp:LinqDataSource AutoSort="True|False" />

Property Value

Type: System.Boolean
true if the user can sort the data; otherwise, false. The default value is true.

The LinqDataSource control supports two approaches for sorting data. You can use the AutoSort property to enable run-time sorting or you can set the OrderBy property to define the sorting at design time.

Set the AutoSort property to true to enable sorting in a LinqDataSource control that is based on the sort expression from a data-bound control. The data-bound control provides the interface to enable the user to select at run time which property to use for sorting.

You can programmatically set the order in which data is returned by setting the OrderBy property to the property or properties used for sorting. When the OrderBy property is set to a property and the AutoSort property is true, the sort expression from the data-bound control is applied after the expression in the OrderBy property. Therefore, this determines the final sorting of the data.

The following example shows a LinqDataSource control with the AutoSort property set to true and a GridView control that is bound to the LinqDataSource control. The AllowSorting property of the GridView control is set to true to provide the interface that lets users sort the data.


Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5