LinqDataSourceSelectEventArgs.WhereParameters Property

 
System_CAPS_noteNote

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

Gets the collection of parameters that is used to create the Where clause.

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

public IDictionary<string, object> WhereParameters { get; }

Property Value

Type: System.Collections.Generic.IDictionary<String, Object>

An object that contains the parameters for the Where clause.

You use the WhereParameters property to access parameters for the Where clause in a handler for the Selecting event. You can modify the Where clause by adding or removing parameters from this collection. By default, the WhereParameters property of the LinqDataSourceSelectEventArgs object contains any parameters that you added to the WhereParameters of the LinqDataSource control.

When you add parameters through the WhereParameters collection of the LinqDataSourceSelectEventArgs object, you must either include a placeholder for the parameter in the Where property or set the AutoGenerateWhereClause property to true. For example, if you add a parameter named ProductName in the event handler for the Selecting event, you must either set the AutoGenerateWhereClause property to true or set the Where property to ProductName=@ProductName.

The following example shows how to add a parameter to the WhereParameters collection. The added parameter will limit the returned products to only those products with a value of "Bike" in the Name property. The AutoGenerateWhereClause property is set to true so that the parameter is automatically included in the Where clause.

<script runat="server">
    protected void LinqDataSource_Selecting(object sender, LinqDataSourceSelectEventArgs e)
    {
        e.WhereParameters.Add("Name", "Bike");
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Example Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:LinqDataSource 
            ContextTypeName="ExampleDataContext" 
            TableName="Products" 
            AutoGenerateWhereClause="true" 
            OnSelecting="LinqDataSource_Selecting" 
            ID="LinqDataSource1" 
            runat="server">
        </asp:LinqDataSource>
        <asp:GridView 
            DataSourceID="LinqDataSource1" 
            ID="GridView1" 
            runat="server">
        </asp:GridView>
    </div>
    </form>
</body>
</html>

.NET Framework
Available since 3.5
Return to top
Show: