Assembly: System.Web.Extensions (in System.Web.Extensions.dll)
Property ValueType: System.Boolean
true if the LinqDataSource control will create the Where clause; otherwise, false. The default is false.
When you set the 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 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 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 property is true, because the parser dynamically creates the Where clause. The LinqDataSource control throws an exception if the property is true and the Where property is assigned values.
The following example shows a LinqDataSource control with the 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.
<asp:DropDownList AutoPostBack="true" ID="DropDownList1" runat="server"> <asp:ListItem Value="Sports"></asp:ListItem> <asp:ListItem Value="Garden"></asp:ListItem> <asp:ListItem Value="Auto"></asp:ListItem> </asp:DropDownList> <asp:LinqDataSource ContextTypeName="ExampleDataContext" TableName="Products" AutoGenerateWhereClause="true" ID="LinqDataSource1" runat="server"> <WhereParameters> <asp:ControlParameter Name="Category" ControlID="DropDownList1" Type="String" /> </WhereParameters> </asp:LinqDataSource> <asp:GridView DataSourceID="LinqDataSource1" ID="GridView1" runat="server"> </asp:GridView>
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