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

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

ObjectDataSourceView.FilterExpression プロパティ

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

SelectMethod プロパティ指定されビジネス オブジェクト メソッド呼び出し時に適用されるフィルタ処理式を取得または設定します

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

Public Property FilterExpression As
 String
Dim instance As ObjectDataSourceView
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)

プロパティ
SelectMethod プロパティ指定されビジネス オブジェクト メソッド使用してデータ取得するときに適用されるフィルタ処理式を表す文字列。

例外例外
例外種類条件

NotSupportedException

FilterExpression プロパティ設定されていますが、Select メソッドDataSet返しません。

解説解説

ObjectDataSource コントロールデータフィルタ処理サポートするのは、Select メソッドDataSet、DataView、DataTable の各オブジェクト返す場合だけです。

FilterExpression プロパティ使用されている構文は、書式指定文字列スタイルの式です。フィルタ式は、Select メソッド実行返される DataView オブジェクトの RowFilter プロパティ適用されるため、フィルタ式の構文は、RowFilter プロパティ受け入れられる構文と同じです (詳細については、Expressionトピック参照してください)。パラメータを FilterParameters コレクション追加する場合パラメータ値を置換する式に、"{0}" などの書式指定文字列プレースホルダを含めることもできます。このプレースホルダは、FilterParameters コレクション内のパラメータインデックスに従って置き換えられます。

FilterExpression には、パラメータ使用できますパラメータデータ型文字列型または文字型の場合パラメータ単一引用符囲みますパラメータ数値型場合引用符不要です。FilterParameters コレクションは、FilterExpression にあるプレースホルダに対して評価する対象パラメータ格納します

FilterExpression プロパティの値はビューステート格納されます。

セキュリティに関するメモセキュリティに関するメモ

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

使用例使用例

このセクションには、2 つコード例含まれています。中間層ビジネス オブジェクトおよび GridView コントロールから、ObjectDataSource コントロール使用してデータ取得しフィルタ処理済みデータ表示する方法最初コード例示します2 つ目のコード例では、1 つ目のコード例使用されている中間層ビジネス オブジェクトの例を示します

中間層ビジネス オブジェクトおよび GridView コントロールから、ObjectDataSource コントロール使用してデータ取得しフィルタ処理済みデータ表示する方法次のコード例示しますObjectDataSource コントロールデータフィルタ処理できるのは、データ取得するメソッドデータDataSet オブジェクトとして取得する場合だけです。このためSelectMethod プロパティは、データDataSet として取得するビジネス オブジェクト メソッド識別します。

このコード例は、TextBoxGridView コントロールObjectDataSource コントロール、および [Submit] ボタン構成されます。既定では、TextBox にはいずれかの Northwind Traders 従業員の名前が設定されます。GridView には、TextBox 内の名前で識別される従業員情報表示されます。他の従業員データ取得するには、TextBox目的従業員フルネーム入力して [Submit] ボタンクリックします。

FilterExpression プロパティは、SelectMethod プロパティによって取得されデータフィルタ処理をするための式を指定します。FilterParameters コレクション含まれるパラメータ評価されるパラメータ プレースホルダを使用します。この例では、パラメータの型が文字列型 (スペース含まれる場合がある) であるため、パラメータ プレースホルダは単一引用符囲まれます。パラメータデータ型数値型または日付型場合引用符不要です。

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB"
 Assembly="Samples.AspNet.VB"
 %>
<%@ Page language="vb" %>
<script runat="server">

    Protected Sub ObjectDataSource1_Filtering(ByVal
 sender As Object, ByVal
 e As System.Web.UI.WebControls.ObjectDataSourceFilteringEventArgs)
        If Textbox1.Text = "" Then
            e.ParameterValues.Clear()
            e.ParameterValues.Add("FullName", "Nancy
 Davolio")
        End If
    End Sub
</script>

<html>
  <head>
    <title>ObjectDataSource - VB Example</title>
  </head>
  <body>
    <form id="Form1" method="post"
 runat="server">

        <p>Show all users with the following name.</p>

        <asp:textbox id="Textbox1" runat="server"
 text="Nancy Davolio" />

        <asp:gridview
          id="GridView1"
          runat="server"
          datasourceid="ObjectDataSource1"
          autogeneratecolumns="False">
          <columns>
            <asp:boundfield headertext="ID" datafield="EmpID"
 />
            <asp:boundfield headertext="Name" datafield="FullName"
 />
            <asp:boundfield headertext="Street Address"
 datafield="Address" />
          </columns>
        </asp:gridview>

        <!-- Security Note: The ObjectDataSource uses a FormParameter,
             Security Note: which does not perform validation
 of input from the client. -->

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetAllEmployeesAsDataSet"
          typename="Samples.AspNet.VB.EmployeeLogic"
          filterexpression="FullName='{0}'" OnFiltering="ObjectDataSource1_Filtering">
            <filterparameters>
              <asp:formparameter name="FullName"
 formfield="Textbox1" defaultvalue="Nancy
 Davolio" />
            </filterparameters>
        </asp:objectdatasource>

        <p><asp:button id="Button1" runat="server"
 text="Search" /></p>

    </form>
  </body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS"
 Assembly="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<script runat="server">

    protected void ObjectDataSource1_Filtering(object
 sender, ObjectDataSourceFilteringEventArgs e)
    {
        if (Textbox1.Text == "")
        {
            e.ParameterValues.Clear();
            e.ParameterValues.Add("FullName", "Nancy Davolio");
        }
    }
</script>

<html>
  <head>
    <title>ObjectDataSource - C# Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">

        <p>Show all users with the following name.</p>

        <asp:textbox id="Textbox1" runat="server" text="Nancy
 Davolio" />

        <asp:gridview
          id="GridView1"
          runat="server"
          datasourceid="ObjectDataSource1"
          autogeneratecolumns="False">
          <columns>
            <asp:boundfield headertext="ID" datafield="EmpID"
 />
            <asp:boundfield headertext="Name" datafield="FullName"
 />
            <asp:boundfield headertext="Street Address" datafield="Address"
 />
          </columns>
        </asp:gridview>

        <!-- Security Note: The ObjectDataSource uses a FormParameter,
             Security Note: which does not perform validation of input from the client.
 -->

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetAllEmployeesAsDataSet"
          typename="Samples.AspNet.CS.EmployeeLogic"
          filterexpression="FullName='{0}'" OnFiltering="ObjectDataSource1_Filtering">
            <filterparameters>
              <asp:formparameter name="FullName" formfield="Textbox1"
 defaultvalue="Nancy Davolio" />
            </filterparameters>
        </asp:objectdatasource>

        <p><asp:button id="Button1" runat="server" text="Search"
 /></p>

    </form>
  </body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL"
 Assembly="Samples.AspNet.JSL" %>
<%@ Page language="VJ#" %>
<script runat="server">

    protected void ObjectDataSource1_Filtering(Object
 sender, ObjectDataSourceFilteringEventArgs e)
    {
        if (Textbox1.get_Text() == "")
        {
            e.get_ParameterValues().Clear();
            e.get_ParameterValues().Add("FullName", "Nancy Davolio");
        }
    }
</script>

<html>
  <head>
    <title>ObjectDataSource - VJ# Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">

        <p>Show all users with the following name.</p>

        <asp:textbox id="Textbox1" runat="server" text="Nancy
 Davolio" />

        <asp:gridview
          id="GridView1"
          runat="server"
          datasourceid="ObjectDataSource1"
          autogeneratecolumns="False">
          <columns>
            <asp:boundfield headertext="ID" datafield="EmpID"
 />
            <asp:boundfield headertext="Name" datafield="FullName"
 />
            <asp:boundfield headertext="Street Address" datafield="Address"
 />
          </columns>
        </asp:gridview>

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetAllEmployeesAsDataSet"
          typename="Samples.AspNet.JSL.EmployeeLogic"
          filterexpression="FullName='{0}'" OnFiltering="ObjectDataSource1_Filtering">
            <filterparameters>
              <asp:formparameter name="FullName" formfield="Textbox1"
 defaultvalue="Nancy Davolio" />
            </filterparameters>
        </asp:objectdatasource>

        <p><asp:button id="Button1" runat="server" text="Search"
 /></p>

    </form>
  </body>
</html>

前のコード例使用した中間層ビジネス オブジェクトの例を提供するコード例次に示します。このコード例は、次の 2 つ基本クラス構成されます。

説明簡略化するために、EmployeeLogic クラスは、データ層からデータ取得する代わりに静的データセット作成します。この例ではユーザー指定した Northwind Traders の従業員フル ネーム使用してフィルタ処理実行するため、この例でも便利な方法です。

実際に動作させるためには、これらのクラスコンパイルし、提供されWeb フォームページ コード例組み合わせて使用する必要があります

Imports System
Imports System.Collections
Imports System.Data
Imports System.Web.UI.WebControls

Namespace Samples.AspNet.VB
'
' EmployeeLogic is a stateless business object that encapsulates 
' the operations you can perform on a NorthwindEmployee object.
'
Public Class EmployeeLogic
   
   ' Returns a collection of NorthwindEmployee objects.
   Public Shared Function
 GetAllEmployees() As ICollection
      Dim data As New ArrayList()
      
      data.Add(New NorthwindEmployee(1, "Nancy",
 "Davolio", "507 - 20th Ave. E.
 Apt. 2A"))
      data.Add(New NorthwindEmployee(2, "Andrew",
 "Fuller", "908 W. Capital Way"))
      data.Add(New NorthwindEmployee(3, "Janet",
 "Leverling", "722 Moss Bay Blvd."))
      data.Add(New NorthwindEmployee(4, "Margaret",
 "Peacock", "4110 Old Redmond
 Rd."))
      data.Add(New NorthwindEmployee(5, "Steven",
 "Buchanan", "14 Garrett Hill"))
      data.Add(New NorthwindEmployee(6, "Michael",
 "Suyama", "Coventry House Miner
 Rd."))
      data.Add(New NorthwindEmployee(7, "Robert",
 "King", "Edgeham Hollow Winchester
 Way"))
      
      Return data
   End Function 'GetAllEmployees
   
   
   Public Shared Function
 GetEmployee(anID As Object) As
 NorthwindEmployee
      Dim data As ArrayList = CType(GetAllEmployees(),
 ArrayList)
      Dim empID As Integer
 = Int32.Parse(anID.ToString())
      Return CType(data(empID),NorthwindEmployee)   
   End Function 'GetEmployee
   
   
   ' To support basic filtering, the employees cannot
   ' be returned as an array of objects, rather as a 
   ' DataSet of the raw data values. 
   Public Shared Function
 GetAllEmployeesAsDataSet() As DataSet
      Dim employees As ICollection = GetAllEmployees()
      
      Dim ds As New DataSet("Table")
      
      ' Create the schema of the DataTable.
      Dim dt As New DataTable()
      Dim dc As DataColumn
      dc = New DataColumn("EmpID",
 GetType(Integer))
      dt.Columns.Add(dc)
      dc = New DataColumn("FullName",
 GetType(String))
      dt.Columns.Add(dc)
      dc = New DataColumn("Address",
 GetType(String))
      dt.Columns.Add(dc)
      
      ' Add rows to the DataTable.
      Dim row As DataRow
      Dim ne As NorthwindEmployee
      For Each ne In employees
         
         row = dt.NewRow()
         row("EmpID") = ne.EmpID
         row("FullName") = ne.FullName
         row("Address") = ne.Address
         dt.Rows.Add(row)
      Next
      ' Add the complete DataTable to the DataSet.
      ds.Tables.Add(dt)
      
      Return ds
   End Function 'GetAllEmployeesAsDataSet
      
End Class 'EmployeeLogic 


Public Class NorthwindEmployee
   
   Public Sub New(anID As
 Integer, aFirstName As String,
 aLastName As String, anAddress As String)
      ID = anID
      Me.aFirstName = aFirstName
      Me.aLastName = aLastName
      Me.aAddress = anAddress
   End Sub 'New
   
   Private ID As Object
   
   Public ReadOnly Property
 EmpID() As String
      Get
         Return ID.ToString()
      End Get
   End Property 

   Private aLastName As String
   
   Public Property LastName() As
 String
      Get
         Return aLastName
      End Get
      Set
         aLastName = value
      End Set
   End Property 

   Private aFirstName As String
   
   Public Property FirstName() As
 String
      Get
         Return aFirstName
      End Get
      Set
         aFirstName = value
      End Set
   End Property 
   
   Public ReadOnly Property
 FullName() As String
      Get
         Return FirstName & " "
 & LastName
      End Get
   End Property 
  
   Private aAddress As String
  
   Public Property Address() As
 String
      Get
         Return aAddress
      End Get
      Set
         aAddress = value
      End Set
   End Property 
   
End Class 'NorthwindEmployee
End Namespace
namespace Samples.AspNet.CS {

using System;
using System.Collections;
using System.Data;
using System.Web.UI.WebControls;
  //
  // EmployeeLogic is a stateless business object that encapsulates
 
  // the operations you can perform on a NorthwindEmployee object.
  //
  public class EmployeeLogic {
  
    
    // Returns a collection of NorthwindEmployee objects.
    public static ICollection GetAllEmployees
 () {
      ArrayList data = new ArrayList();
           
      data.Add(new NorthwindEmployee(1,"Nancy","Davolio","507
 - 20th Ave. E. Apt. 2A"));
      data.Add(new NorthwindEmployee(2,"Andrew","Fuller","908
 W. Capital Way"));
      data.Add(new NorthwindEmployee(3,"Janet","Leverling","722
 Moss Bay Blvd."));
      data.Add(new NorthwindEmployee(4,"Margaret","Peacock","4110
 Old Redmond Rd."));
      data.Add(new NorthwindEmployee(5,"Steven","Buchanan","14
 Garrett Hill"));
      data.Add(new NorthwindEmployee(6,"Michael","Suyama","Coventry
 House Miner Rd."));
      data.Add(new NorthwindEmployee(7,"Robert","King","Edgeham
 Hollow Winchester Way"));
      
      return data;
    }
    
    public static NorthwindEmployee GetEmployee(object
 anID) {
      ArrayList data = GetAllEmployees() as ArrayList;     
      int empID = Int32.Parse(anID.ToString());      
      return data[empID] as NorthwindEmployee;
    }

    // 
    // To support basic filtering, the employees cannot
    // be returned as an array of objects, rather as a 
    // DataSet of the raw data values. 
    public static DataSet GetAllEmployeesAsDataSet
 () {
      ICollection employees = GetAllEmployees();
      
      DataSet ds = new DataSet("Table");
      
      // Create the schema of the DataTable.
      DataTable dt = new DataTable();
      DataColumn dc;
      dc = new DataColumn("EmpID",   typeof(int));
    dt.Columns.Add(dc);
      dc = new DataColumn("FullName",typeof(string));
 dt.Columns.Add(dc);
      dc = new DataColumn("Address", typeof(string));
 dt.Columns.Add(dc);
      
      // Add rows to the DataTable.
      DataRow row;
            
      foreach (NorthwindEmployee ne in employees)
 {                
        row = dt.NewRow();
        row["EmpID"]    = ne.EmpID;
        row["FullName"] = ne.FullName;
        row["Address"]  = ne.Address;
        dt.Rows.Add(row);
      } 
      // Add the complete DataTable to the DataSet.
      ds.Tables.Add(dt);
      
      return ds;
    }    
  }

  public class NorthwindEmployee {

    public NorthwindEmployee (int anID, 
                              string aFirstName,
                              string aLastName,
                              string anAddress) {
      ID = anID;
      firstName = aFirstName;
      lastName = aLastName;   
      address = anAddress;
    }

    private object ID;
    public string EmpID {
      get { return ID.ToString();  }
    }

    private string lastName;
    public string LastName {
      get { return lastName; }
      set { lastName = value; }
    }

    private string firstName;
    public string FirstName {
      get { return firstName; }
      set { firstName = value;  }
    }
    
    public string FullName {
      get { return FirstName  + " "
 +  LastName; }
    }
    
    private string address;
    public string Address {
      get { return address; }
      set { address = value;  }
    }    
    
  }
}
package Samples.AspNet.JSL ; 
import System .* ;
import System.Collections .* ;
import System.Data .* ;
import System.Web.UI.WebControls .* ;
//
// EmployeeLogic is a stateless business object that encapsulates 
// the operations you can perform on a NorthwindEmployee object.
//
public class EmployeeLogic
{
    // Returns a collection of NorthwindEmployee objects.
    public static ICollection GetAllEmployees()
    {
        ArrayList data = new ArrayList();

        data.Add(new NorthwindEmployee(1, "Nancy", "Davolio",
 
            "507 - 20th Ave. E. Apt. 2A"));
        data.Add(new NorthwindEmployee(2, "Andrew",
 "Fuller", 
            "908 W. Capital Way"));
        data.Add(new NorthwindEmployee(3, "Janet", "Leverling",
 
            "722 Moss Bay Blvd."));
        data.Add(new NorthwindEmployee(4, "Margaret",
 "Peacock", 
            "4110 Old Redmond Rd."));
        data.Add(new NorthwindEmployee(5, "Steven",
 "Buchanan", 
            "14 Garrett Hill"));
        data.Add(new NorthwindEmployee(6, "Michael",
 "Suyama", 
            "Coventry House Miner Rd."));
        data.Add(new NorthwindEmployee(7, "Robert",
 "King", 
            "Edgeham Hollow Winchester Way"));
        return data;
    } //GetAllEmployees


    public static NorthwindEmployee GetEmployee(Object
 anID)
    {
        ArrayList data = (ArrayList)GetAllEmployees();
        int empID = Int32.Parse(String.valueOf(anID));

        return (NorthwindEmployee)data.get_Item(empID);
    } //GetEmployee


    // 
    // To support basic filtering, the employees cannot
    // be returned as an array of objects, rather as a 
    // DataSet of the raw data values. 
    public static DataSet GetAllEmployeesAsDataSet()
    {
        ICollection employees = GetAllEmployees();
        DataSet ds = new DataSet("Table");

        // Create the schema of the DataTable.
        DataTable dt = new DataTable();
        DataColumn dc;

        dc = new DataColumn("EmpID", int.class.ToType());
        dt.get_Columns().Add(dc);
        dc = new DataColumn("FullName", String.class.ToType());
        dt.get_Columns().Add(dc);
        dc = new DataColumn("Address", String.class.ToType());
        dt.get_Columns().Add(dc);

        // Add rows to the DataTable.
        DataRow row;

        IEnumerator iterator = employees.GetEnumerator();
        for (int iCtr = 0; iCtr < employees.get_Count();
 iCtr++) {
            iterator.MoveNext();
            NorthwindEmployee ne = 
                (NorthwindEmployee)iterator.get_Current();

            row = dt.NewRow();
            row.set_Item("EmpID", ne.get_EmpID());
            row.set_Item("FullName", ne.get_FullName());
            row.set_Item("Address", ne.get_Address());
            dt.get_Rows().Add(row);
        }

        // Add the complete DataTable to the DataSet.
        ds.get_Tables().Add(dt);
        return ds;
    } //GetAllEmployeesAsDataSet
} //EmployeeLogic



public class NorthwindEmployee
{
    public NorthwindEmployee(int anID, String
 aFirstName, String aLastName, 
        String anAddress)
    {
        ID = new Integer(anID);
        firstName = aFirstName;
        lastName = aLastName;
        address = anAddress;
    } //NorthwindEmployee


    private Object ID;


    /** @property */
    public String get_EmpID()
    {
        return ID.toString();
    } //get_EmpID


    private String lastName;


    /** @property */
    public String get_LastName()
    {
        return lastName;
    } //get_LastName


    /** @property */
    public void set_LastName(String value)
    {
        lastName = value;
    } //set_LastName


    private String firstName;


    /** @property */
    public String get_FirstName()
    {
        return firstName;
    } //get_FirstName


    /** @property */
    public void set_FirstName(String value)
    {
        firstName = value;
    } //set_FirstName


    /** @property */
    public String get_FullName()
    {
        return firstName + " " + lastName;
    } //get_FullName


    private String address;


    /** @property */
    public String get_Address()
    {
        return address;
    } //get_Address


    /** @property */
    public void set_Address(String value)
    {
        address = value;
    } //set_Address
} //NorthwindEmployee
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ObjectDataSourceView クラス
ObjectDataSourceView メンバ
System.Web.UI.WebControls 名前空間
FilterParameters



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

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

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

   

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



ObjectDataSourceView.FilterExpression プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS