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

Dim instance As SqlDataSourceView Dim value As String value = instance.FilterExpression instance.FilterExpression = value
/** @property */ public String get_FilterExpression () /** @property */ public void set_FilterExpression (String value)
public function get FilterExpression () : String public function set FilterExpression (value : String)
Select メソッドを使用してデータを取得するときに適用される、フィルタ処理式を表す文字列。


FilterExpression プロパティに使用されている構文は、書式指定文字列スタイルの構文です。FilterExpression プロパティには、パラメータを使用できます。パラメータのデータ型が文字列または文字の場合、パラメータを単一引用符で囲みます。パラメータが数値型の場合、引用符は不要です。
FilterParameters コレクションは、FilterExpression プロパティで見つかったプレースホルダについて評価されるパラメータを格納します。
SqlDataSource コントロールがデータのフィルタ処理をサポートするのは、DataSet モードの場合だけです。
FilterExpression プロパティの値はビューステートに格納されます。
![]() |
---|
クライアントから受け取ったフィルタ パラメータ値を検証する必要があります。ランタイムは、パラメータ値をフィルタ式に代入して、Select メソッドによって返される DataView オブジェクトに適用します。FilterExpression プロパティをセキュリティ対策として使用して、返されるアイテムの数を制限している場合は、フィルタ処理が行われる前に、パラメータ値を検証する必要があります。 |

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- SqlDataSourceView.FilterExpression プロパティのページへのリンク