SqlDataSource.FilterParameters 属性

定义

获取与 FilterExpression 字符串中的任何参数占位符关联的参数的集合。Gets a collection of parameters that are associated with any parameter placeholders that are in the FilterExpression string.

public:
 property System::Web::UI::WebControls::ParameterCollection ^ FilterParameters { System::Web::UI::WebControls::ParameterCollection ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.ParameterCollection FilterParameters { get; }
member this.FilterParameters : System.Web.UI.WebControls.ParameterCollection
Public ReadOnly Property FilterParameters As ParameterCollection

属性值

ParameterCollection,它包含与在 FilterExpression 属性中找到的任何参数占位符相关联的一组参数。A ParameterCollection that contains a set of parameters associated with any parameter placeholders found in the FilterExpression property.

属性

示例

下面的代码示例演示如何使用FilterExpressionFilterParameters属性从 Northwind 数据库中检索数据并对其进行筛选。The following code example demonstrates how to retrieve data from the Northwind database and filter it using the FilterExpression and FilterParameters properties. 只要FilterExpression执行Select方法来SqlDataSource检索数据, 就会应用控件的属性。The FilterExpression property of the SqlDataSource control is applied anytime the Select method is executed to retrieve data. 在此示例中, FilterExpression属性包含一个筛选器参数的占位符, 该参数包含FilterParameters在集合中。In this example, the FilterExpression property contains a placeholder for a filter parameter, which is contained in the FilterParameters collection. 此外, 筛选器参数是一个ControlParameter对象, 该对象绑定SelectedValueDropDownList控件的属性。In addition, the filter parameter is a ControlParameter object that is bound to the SelectedValue property of the DropDownList control. AutoPostBack true DropDownList由于控件将其属性设置为, 因此, 所选内容中的任何更改都会导致页面将信息发送回服务器, GridView并将控件重新绑定到数据源控件DropDownList新建筛选器。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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="form1" runat="server">

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

            <asp:SqlDataSource
                id="SqlDataSource1"
                runat="server"
                ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
                SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
                FilterExpression="Title='{0}'">
                <FilterParameters>
                    <asp:ControlParameter Name="Title" ControlId="DropDownList1" PropertyName="SelectedValue"/>
                </FilterParameters>
            </asp:SqlDataSource>

            <p><asp:GridView
                id="GridView1"
                runat="server"
                DataSourceID="SqlDataSource1"
                AutoGenerateColumns="False">
                <columns>
                    <asp:BoundField Visible="False" DataField="EmployeeID" />
                    <asp:BoundField HeaderText="First Name" DataField="FirstName" />
                    <asp:BoundField HeaderText="Last Name" DataField="LastName" />
                </columns>
            </asp:GridView></p>

        </form>
    </body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="form1" runat="server">

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

            <asp:SqlDataSource
                id="SqlDataSource1"
                runat="server"
                ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
                SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
                FilterExpression="Title='{0}'">
                <FilterParameters>
                    <asp:ControlParameter Name="Title" ControlId="DropDownList1" PropertyName="SelectedValue"/>
                </FilterParameters>
            </asp:SqlDataSource>

            <p><asp:GridView
                id="GridView1"
                runat="server"
                DataSourceID="SqlDataSource1"
                AutoGenerateColumns="False">
                <columns>
                    <asp:BoundField Visible="False" DataField="EmployeeID" />
                    <asp:BoundField HeaderText="First Name" DataField="FirstName" />
                    <asp:BoundField HeaderText="Last Name" DataField="LastName" />
                </columns>
            </asp:GridView></p>

        </form>
    </body>
</html>

注解

FilterParameters集合中的参数与FilterExpression属性中指定的任何参数相关联。The parameters in the FilterParameters collection are associated with any parameters that are specified in the FilterExpression property. 调用FilterExpression 方法Select时, 属性中指定的参数占位符按顺序与集合中的FilterParameters参数对象匹配。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.

SqlDataSourceView属性检索与SqlDataSource控件相关联的对象所包含的属性。FilterParameters FilterParametersThe FilterParameters property retrieves the FilterParameters property that is contained by the SqlDataSourceView object that is associated with the SqlDataSource control.

重要

无需验证即可将值插入到参数中, 这是一个潜在的安全威胁。Values are inserted into parameters without validation, which is a potential security threat. Filtering使用事件在执行查询之前验证参数值。Use the Filtering event to validate parameter values before executing the query. 有关详细信息,请参阅脚本侵入概述For more information, see Script Exploits Overview.

适用于

另请参阅