FilterParameters Property

SqlDataSource.FilterParameters Property


Gets a collection of parameters that are associated with any parameter placeholders that are in the FilterExpression string.

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

public ParameterCollection FilterParameters { get; }

Property Value

Type: System.Web.UI.WebControls.ParameterCollection

A ParameterCollection that contains a set of parameters associated with any parameter placeholders found in the FilterExpression property.

The parameters in the FilterParameters collection are associated with any parameters that are specified in the FilterExpression property. The parameter placeholders that are specified in the FilterExpression property are matched by order to parameter objects in the FilterParameters collection when the Select method is called.

The FilterParameters property retrieves the FilterParameters property that is contained by the SqlDataSourceView object that is associated with the SqlDataSource control.

System_CAPS_security Security Note

Values are inserted into parameters without validation, which is a potential security threat. Use the Filtering event to validate parameter values before executing the query. For more information, see Script Exploits Overview.

The following code example demonstrates how to retrieve data from the Northwind database and filter it using the FilterExpression and FilterParameters properties. The FilterExpression property of the SqlDataSource control is applied anytime the Select method is executed to retrieve data. In this example, the FilterExpression property contains a placeholder for a filter parameter, which is contained in the FilterParameters collection. In addition, the filter parameter is a ControlParameter object that is bound to the SelectedValue property of the DropDownList control. Because the DropDownList control has its AutoPostBack property set to true, any change in the DropDownList selection causes the page to post information back to the server and the GridView control to rebind to the data source control with the new filter.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
    <head runat="server">
    <title>ASP.NET Example</title>
        <form id="form1" runat="server">

            <p>Show all employees with the following title:
                <asp:ListItem Selected="True">Sales Representative</asp:ListItem>
                <asp:ListItem>Sales Manager</asp:ListItem>
                <asp:ListItem>Vice President, Sales</asp:ListItem>

                ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
                SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
                    <asp:ControlParameter Name="Title" ControlId="DropDownList1" PropertyName="SelectedValue"/>

                    <asp:BoundField Visible="False" DataField="EmployeeID" />
                    <asp:BoundField HeaderText="First Name" DataField="FirstName" />
                    <asp:BoundField HeaderText="Last Name" DataField="LastName" />


.NET Framework
Available since 2.0
Return to top
© 2015 Microsoft