Export (0) Print
Expand All

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.

<asp:LinqDataSource 
    ContextTypeName="ExampleDataContext" 
    TableName="Products" 
    AutoPage="true"
    AutoSort="true"
    ID="LinqDataSource1" 
    runat="server">
</asp:LinqDataSource>
<asp:GridView 
    AllowPaging="true"
    AllowSorting="true"
    DataSourceID="LinqDataSource1"
    ID="GridView1" 
    runat="server">
</asp:GridView>

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft