Modifier

Partager via


LinqDataSource.AutoGenerateOrderByClause Property

Definition

Gets or sets a value that indicates whether the LinqDataSource control dynamically creates an Order By clause based on values in the OrderByParameters collection.

public:
 property bool AutoGenerateOrderByClause { bool get(); void set(bool value); };
public bool AutoGenerateOrderByClause { get; set; }
member this.AutoGenerateOrderByClause : bool with get, set
Public Property AutoGenerateOrderByClause As Boolean

Property Value

true if the LinqDataSource control creates the Order By clause; otherwise, false. The default is false.

Examples

The following example shows a LinqDataSource control with the AutoGenerateOrderByClause set to true. A parameter is included in the OrderByParameters collection that orders the data based on the property name that a user selects from a DropDownList control.

<asp:DropDownList AutoPostBack="true" ID="DropDownList1" runat="server">
    <asp:ListItem Value="Category"></asp:ListItem>
    <asp:ListItem Value="Price"></asp:ListItem>
</asp:DropDownList>
<asp:LinqDataSource 
    ContextTypeName="ExampleDataContext" 
    TableName="Products" 
    AutoGenerateOrderByClause="true"
    ID="LinqDataSource1" 
    runat="server">
    <OrderByParameters>
      <asp:ControlParameter
         ControlID="DropDownList1" 
         Type="String" />
    </OrderByParameters>
</asp:LinqDataSource>
<asp:GridView 
    DataSourceID="LinqDataSource1"
    ID="GridView1" 
    runat="server">
</asp:GridView>
<asp:DropDownList AutoPostBack="true" ID="DropDownList1" runat="server">
    <asp:ListItem Value="Category"></asp:ListItem>
    <asp:ListItem Value="Price"></asp:ListItem>
</asp:DropDownList>
<asp:LinqDataSource 
    ContextTypeName="ExampleDataContext" 
    TableName="Products" 
    AutoGenerateOrderByClause="true"
    ID="LinqDataSource1" 
    runat="server">
    <OrderByParameters>
      <asp:ControlParameter
         ControlID="DropDownList1" 
         Type="String" />
    </OrderByParameters>
</asp:LinqDataSource>
<asp:GridView 
    DataSourceID="LinqDataSource1"
    ID="GridView1" 
    runat="server">
</asp:GridView>

Remarks

When you set the AutoGenerateOrderByClause property to true, the LinqDataSource control dynamically creates an Order By clause that is based on the values in the OrderByParameters collection. The LinqDataSource control sorts the data by the first parameter and then additionally sorts the data for each additional parameter. Parameters that contain null or an empty value are not included in the Order By clause.

You do not set the OrderBy property when the AutoGenerateOrderByClause is set to true, because the parser dynamically creates the Order By clause. The LinqDataSource control throws an exception if the AutoGenerateOrderByClause is set to true and the OrderBy property is assigned values.

Applies to