EntityDataSource.AutoGenerateOrderByClause Property

 

Gets or sets a value that indicates whether the EntityDataSource control dynamically creates an ORDER BY clause based on values in the OrderByParameters collection.

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

public bool AutoGenerateOrderByClause { get; set; }

Property Value

Type: System.Boolean

true if the EntityDataSource control creates the ORDER BY clause; otherwise, false. The default value is false.

Exception Condition
InvalidOperationException

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

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.

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>

.NET Framework
Available since 3.5
Return to top
Show: