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; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.FilterParameters : System.Web.UI.WebControls.ParameterCollection
Public ReadOnly Property FilterParameters As ParameterCollection

屬性值

ParameterCollection

ParameterCollection,其中所包含的一組參數,與在 FilterExpression 屬性中找到的任何參數預留位置相關聯。A ParameterCollection that contains a set of parameters associated with any parameter placeholders found in the FilterExpression property.

屬性

範例

下列程式碼範例示範如何從 Northwind 資料庫取出資料,並使用和屬性進行篩選 FilterExpression FilterParametersThe following code example demonstrates how to retrieve data from the Northwind database and filter it using the FilterExpression and FilterParameters properties. FilterExpression SqlDataSource 每當 Select 執行方法來取出資料時,就會套用控制項的屬性。The FilterExpression property of the SqlDataSource control is applied anytime the Select method is executed to retrieve data. 在此範例中, FilterExpression 屬性包含包含在集合中之篩選參數的預留位置 FilterParametersIn this example, the FilterExpression property contains a placeholder for a filter parameter, which is contained in the FilterParameters collection. 此外,篩選參數是系結 ControlParameterSelectedValue 控制項屬性的物件 DropDownListIn addition, the filter parameter is a ControlParameter object that is bound to the SelectedValue property of the DropDownList control. 由於 DropDownList 控制項的 AutoPostBack 屬性設定為,因此 true 選取範圍中的任何變更 DropDownList 都會使頁面將資訊回傳至伺服器,並 GridView 使用新的篩選器重新系結至資料來源控制項。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 與屬性中指定的任何參數相關聯 FilterExpressionThe parameters in the FilterParameters collection are associated with any parameters that are specified in the FilterExpression property. 當呼叫方法時,屬性中指定的參數預留位置 FilterExpression 會依順序與集合中的參數物件相符 FilterParameters SelectThe 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.

屬性會抓取 FilterParameters FilterParameters SqlDataSourceView 與控制項相關聯的物件所包含的屬性 SqlDataSourceThe 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. 如需詳細資訊,請參閱 Script Exploits Overview (指令碼攻擊概觀)。For more information, see Script Exploits Overview.

適用於

另請參閱