Editar

Partilhar via


EntityDataSource.AutoGenerateOrderByClause Property

Definition

Gets or sets a value that indicates whether the EntityDataSource 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 EntityDataSource control creates the ORDER BY clause; otherwise, false. The default value is false.

Exceptions

When the AutoGenerateOrderByClause property is set to true and the OrderBy property is not null.

Examples

The following example automatically generates the ORDER BY clause and uses the value of the OrderByDropDownList to set the value of the parameter.

<asp:DropDownList AutoPostBack="true" ID="OrderByDropDownList" runat="server">
    <asp:ListItem Value="TotalDue"></asp:ListItem>
    <asp:ListItem Value="OrderDate"></asp:ListItem>
</asp:DropDownList>

<asp:EntityDataSource ID="EntityDataSourceWithAutoGenOrderBy" runat="server"
ConnectionString="name=AdventureWorksEntities"
DefaultContainerName="AdventureWorksEntities"
EntitySetName="SalesOrderHeaders"
Select="it.SalesOrderID, it.TotalDue, it.OrderDate"
AutoGenerateOrderByClause="True">
<OrderByParameters>
    <asp:ControlParameter
    ControlID="OrderByDropDownList"/>
</OrderByParameters>
</asp:EntityDataSource>

The following example automatically generates the ORDER BY clause and uses the DefaultValue attribute of the Parameter element to set the value of the parameter.

<asp:EntityDataSource ID="EntityDataSourceWithAutoGenOrderBy" runat="server"
ConnectionString="name=AdventureWorksEntities"
DefaultContainerName="AdventureWorksEntities"
EntitySetName="SalesOrderHeaders"
Select="it.SalesOrderID, it.TotalDue, it.OrderDate"
AutoGenerateOrderByClause="True">
<OrderByParameters>
    <asp:Parameter
    DefaultValue="TotalDue"/>
</OrderByParameters>
</asp:EntityDataSource>

Remarks

When the AutoGenerateOrderByClause property of the EntityDataSource control is set to true, the control automatically generates an ORDER BY clause from the parameter in the ParameterCollection assigned to the OrderByParameters property. This eliminates the need to explicitly assign an ORDER BY clause to the OrderBy property.

If you set the AutoGenerateOrderByClause property to true, you should not explicitly assign a value to the OrderBy property.

Applies to