LinqDataSource.AutoGenerateWhereClause Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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)

abstract AutoGenerateWhereClause : bool with get, set
override AutoGenerateWhereClause : bool with get, set

Property Value

Type: System.Boolean

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

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 null 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
Available since 3.5
Return to top