LinqDataSource.AutoSort Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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; }

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.


.NET Framework
Available since 3.5
Return to top