Export (0) Print
Expand All

LinqDataSource::AutoGenerateWhereClause Property

Gets or sets a value that indicates whether the LinqDataSource control dynamically creates a Where clause based on values defined in the WhereParameters collection.

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

public:
virtual property bool AutoGenerateWhereClause {
	bool get () sealed;
	void set (bool value) sealed;
}
<asp:LinqDataSource AutoGenerateWhereClause="True|False" />

Property Value

Type: System::Boolean
true if the LinqDataSource control will create the Where clause; otherwise, false. The default is false.

Implements

IDynamicDataSource::AutoGenerateWhereClause

When you set the AutoGenerateWhereClause property to true, the LinqDataSource control dynamically creates the Where clause from the parameters in the WhereParameters collection. Each parameter that you add to the WhereParameters collection must have its Name property set to a value that matches a property in the data object that is being queried. The automatically generated Where clause will check whether the value specified in the WhereParameters collection equals the value of the matching property in the data object. If you provide more than one parameter, the parameters are linked with a logical AND operation. Parameters that contain nullptr or an empty value are not included in the Where clause.

The automatically generated Where clause can test only for equality and can link parameters only with the AND operation. Do not set the AutoGenerateWhereClause property to true if you have to add a condition that does not test for equality or if you have to relate parameters with the OR operation. You can accomplish these tasks by setting the AutoGenerateWhereClause property to false and adding placeholders in the Where property for each parameter in the WhereParameters collection. In the Where property, preface each placeholder name with the @ symbol.

You do not set the Where property when the AutoGenerateWhereClause property is true, because the parser dynamically creates the Where clause. The LinqDataSource control throws an exception if the AutoGenerateWhereClause property is true and the Where property is assigned values.

The following example shows a LinqDataSource control with the AutoGenerateWhereClause set to true. A GridView control is bound to the LinqDataSource control to display the data that is returned from the query. A DropDownList control is included that is populated with three values. A parameter is included in the WhereParameters collection with the name set to Category, which matches one of the properties of the data object. Its ControlID property is set to the ID of the DropDownList control. The LinqDataSource control automatically creates the Where property to filter records based on the value that the user selects from the DropDownList control. The query returns the records whose Category property matches the value that the user has selected from the DropDownList control.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.2, 4.5.1, 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