SqlDataSource.FilterExpression プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > SqlDataSource.FilterExpression プロパティの意味・解説 

SqlDataSource.FilterExpression プロパティ

メモ : このプロパティは、.NET Framework version 2.0 で新しく追加されたものです。

Select メソッドの呼び出し時に適用されるフィルタ処理式を取得または設定します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Property FilterExpression As
 String
Dim instance As SqlDataSource
Dim value As String

value = instance.FilterExpression

instance.FilterExpression = value
public string FilterExpression { get;
 set; }
public:
property String^ FilterExpression {
    String^ get ();
    void set (String^ 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 メソッドを使用してデータを取得するときに適用される、フィルタ処理式を表す文字列。

例外例外
例外の種類条件

NotSupportedException

FilterExpression プロパティが設定されており、SqlDataSource が DataReader モードです。

解説解説

FilterExpression プロパティで使用する構文は、書式指定文字列スタイルの式です。フィルタ式は、Select メソッドの実行によって返される DataView オブジェクトの RowFilter プロパティに適用されるため、フィルタ式の構文は、RowFilter プロパティで受け入れられる構文と同じです。詳細については、「Expression」を参照してください。

パラメータを FilterParameters コレクションに追加する場合、パラメータ値を置換する式に書式指定文字列プレースホルダ (たとえば、"{0}") を含めることもできます。このプレースホルダは、FilterParameters コレクション内のパラメータのインデックスに従って置き換えられます。

FilterExpression プロパティには、パラメータを使用できます。パラメータが文字列型または文字型の場合、パラメータを単一引用符で囲みます。パラメータが数値型の場合、引用符は不要です。FilterParameters コレクションは、FilterExpression プロパティで見つかったプレースホルダについて評価されるパラメータを格納します。

SqlDataSource コントロールがデータのフィルタ処理をサポートするのは、DataSet モードの場合だけです。

FilterExpression プロパティは、SqlDataSource コントロールに関連付けられた SqlDataSourceView オブジェクトの FilterExpression プロパティに処理を代行させます。

使用例使用例

Northwind データベースからデータを取得し、FilterExpression 文字列と FilterParameters コレクションを使用してフィルタ処理する方法を次のコード例に示します。Select メソッドを実行してデータを取得するときは常に、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>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SqlDataSource クラス
SqlDataSource メンバ
System.Web.UI.WebControls 名前空間
FilterParameters
SqlDataSource.DataSourceMode プロパティ



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「SqlDataSource.FilterExpression プロパティ」の関連用語

SqlDataSource.FilterExpression プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



SqlDataSource.FilterExpression プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS