SqlDataSourceView.FilterParameters プロパティ

定義

FilterExpression 文字列のパラメーター プレースホルダーに関連付けられたパラメーターのコレクションを取得します。

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

属性

次のコード例は、Northwind データベースからデータを取得し、プロパティをFilterParameters使用してフィルター処理する方法をFilterExpression示しています。 コントロールのプロパティは FilterExpression 、データを SqlDataSource 取得するためにメソッドが Select 実行されるたびに適用されます。 この例では、 FilterExpression プロパティには、コレクションに含まれるフィルター パラメーターのプレースホルダーが FilterParameters 含まれています。 さらに、フィルター パラメーターはControlParameter、コントロールのDropDownListプロパティにSelectedValueバインドされているオブジェクトです。 コントロールの DropDownList プロパティが AutoPostBack 設定 trueされているため、選択内容を DropDownList 変更すると、ページは情報をサーバーにポストバックし、コントロールは GridView 新しいフィルターを使用してデータ ソース コントロールに再バインドされます。

<!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 関連付けられます。 指定FilterExpressionされたパラメーター プレースホルダーは、メソッドの呼び出し時Selectに順序によって評価され、コレクション内のFilterParametersパラメーター オブジェクトと照合されます。

重要

クライアントから受け取るフィルター パラメーター値を検証する必要があります。 ランタイムは、単にパラメーター値をフィルター式に置き換え、メソッドによって返されるオブジェクトにSelect適用しますDataView。 プロパティを FilterExpression セキュリティ対策として使用して、返される項目の数を制限する場合は、フィルター処理が行われる前にパラメーター値を検証する必要があります。

適用対象

こちらもご覧ください