Language

SqlDataSource.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 プロパティで見つかったパラメーター プレースホルダーに関連付けられたパラメーターのセットを含むFilterExpression。

属性

例

次のコード例では、Northwind データベースからデータを取得し、 FilterExpression プロパティと FilterParameters プロパティを使用してフィルター処理する方法を示します。 FilterExpression コントロールの SqlDataSource プロパティは、データを取得するために Select メソッドが実行されるたびに適用されます。 この例では、 FilterExpression プロパティには、 FilterParameters コレクションに含まれるフィルター パラメーターのプレースホルダーが含まれています。 さらに、フィルター パラメーターは、ControlParameter コントロールのSelectedValue プロパティにバインドされているDropDownList オブジェクトです。 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 プロパティで指定されたパラメーター プレースホルダーは、FilterParameters メソッドが呼び出されたときに、Select コレクション内のパラメーター オブジェクトの順序で照合されます。

FilterParameters プロパティは、FilterParameters コントロールに関連付けられているSqlDataSourceView オブジェクトに含まれるSqlDataSource プロパティを取得します。

Important

値は検証なしでパラメーターに挿入されます。これは潜在的なセキュリティ上の脅威です。 Filtering イベントを使用して、クエリを実行する前にパラメーター値を検証します。 詳細については、「スクリプトの 悪用の概要」を参照してください。

適用対象

こちらもご覧ください