SqlDataSource.FilterParameters プロパティ
アセンブリ: System.Web (system.web.dll 内)

FilterExpression プロパティに含まれる任意のパラメータ プレースホルダに関連付けられたパラメータのセットを格納している ParameterCollection。

FilterParameters コレクションのパラメータは、FilterExpression プロパティで指定された任意のパラメータと関連付けられます。FilterExpression プロパティで指定されているパラメータ プレースホルダは、Select メソッドの呼び出し時に、FilterParameters コレクション内のパラメータ オブジェクトと順序に従って照合されます。
FilterParameters プロパティは、SqlDataSource コントロールに関連付けられた SqlDataSourceView オブジェクトが格納する FilterParameters プロパティを取得します。

Northwind データベースからデータを取得し、FilterExpression プロパティと FilterParameters プロパティを使用してフィルタ処理する方法を次のコード例に示します。Select メソッドを実行してデータを取得するときは常に、SqlDataSource コントロールの FilterExpression プロパティが適用されます。この例では、FilterExpression プロパティに、FilterParameters コレクションに格納されているフィルタ パラメータのプレースホルダが格納されています。さらに、フィルタ パラメータは、DropDownList コントロールの SelectedValue プロパティにバインドされている ControlParameter オブジェクトになっています。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> <BODY> <FORM runat="server"> <p>Show all employees with the following title: <asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True"> <asp:ListItem Selected>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> </FORM> </BODY> </HTML>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML> <BODY> <FORM runat="server"> <p>Show all employees with the following title: <asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True"> <asp:ListItem Selected>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> </FORM> </BODY> </HTML>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML> <BODY> <FORM runat="server"> <p>Show all employees with the following title: <asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True"> <asp:ListItem Selected>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="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;" SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees" FilterExpression="Title='@Title'"> <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> </FORM> </BODY> </HTML>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からSqlDataSource.FilterParameters プロパティを検索する場合は、下記のリンクをクリックしてください。

- SqlDataSource.FilterParameters プロパティのページへのリンク