Export (0) Print
Expand All

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; }
<asp:EntityDataSource AutoGenerateOrderByClause="True|False" />

Property Value

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

ExceptionCondition
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

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Community Additions

ADD
Show:
© 2014 Microsoft