ObjectDataSource.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

ParameterCollection 속성에 있는 모든 매개 변수 자리 표시자와 연결된 매개 변수 집합을 포함하는 FilterExpression입니다.

특성

예외

FilterExpression 속성이 설정되어 있고 Select() 메서드에서 DataSet 또는 DataTable을 반환하지 않는 경우

예제

이 섹션에는 두 코드 예제가 있습니다. 첫 번째 코드 예제에 사용 하 여 필터링 된 데이터를 표시 하는 방법을 보여 줍니다.는 ObjectDataSource 중간 계층 비즈니스 개체에서 데이터를 검색 하는 개체 및 GridView 결과 표시 하는 컨트롤입니다. 두 번째 코드 예제에서는 첫 번째 코드 예제에 사용 되는 중간 계층 비즈니스 개체의 예제를 제공 합니다.

다음 코드 예제에 사용 하 여 필터링 된 데이터를 표시 하는 방법을 보여 줍니다.는 ObjectDataSource 중간 계층 비즈니스 개체에서 데이터를 검색 하는 컨트롤 및 GridView 결과 표시 하는 컨트롤입니다. 합니다 ObjectDataSource 제어로 데이터를 검색 하는 메서드를 검색 하는 경우에 데이터를 필터링 할 수는 DataSet 또는 DataTable 개체입니다. 이러한 이유로 합니다 SelectMethod 데이터를 검색 하는 비즈니스 개체 메서드를 식별 하는 속성을 DataSet.

코드 예제에서는 구성를 TextBox 컨트롤을 GridView 컨트롤을 ObjectDataSource 컨트롤 및 제출 단추. 기본적으로 TextBox Northwind Traders 직원 중 하나의 이름으로 채워집니다. 합니다 GridView 에서 이름으로 식별 되는 직원에 대 한 정보를 표시 합니다 TextBox합니다. 다른 직원에 대 한 데이터를 검색할 합니다 TextBox해당 직원의 전체 이름을 입력 하 고 클릭 합니다 제출 단추.

합니다 FilterExpression 속성에서 검색 된 데이터를 필터링 하는 데 사용 되는 식을 지정 합니다 SelectMethod 속성입니다. 에 포함 된 매개 변수를 계산 되는 매개 변수 자리 표시자를 사용 합니다 FilterParameters 컬렉션입니다. 이 예제에서는 매개 변수 자리 표시자는 공백을 포함할 수 있는 문자열 형식 매개 변수 형식의 작은따옴표 제한 됩니다. 매개 변수 형식의 숫자 또는 날짜 형식인 경우에 따옴표가 필요 하지 않습니다. FilterParameters 하나의 매개 변수를 포함 하는 컬렉션을 FormParameter 바인딩되는 개체는 TextBox 컨트롤입니다.

중요

클라이언트에서 받은 모든 필터 매개 변수 값을 확인 해야 합니다. 매개 변수 값은 필터 식으로 대체 및에 적용 하기만 하면 런타임에서 DataView 에서 반환 되는 개체는 Select 메서드. 사용 중인 경우는 FilterExpression 필터링이 발생 하기 전에 매개 변수 값의 유효성을 검사 해야 반환 되는 항목의 수를 제한 하려면 보안 조치로 속성입니다.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 xmlns="http://www.w3.org/1999/xhtml" >
  <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.VB" Assembly="Samples.AspNet.VB" %>
<%@ Page language="vb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 xmlns="http://www.w3.org/1999/xhtml" >
  <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>

다음 코드 예제에서는 앞의 코드 예제를 사용 하는 중간 계층 비즈니스 개체의 예제를 제공 합니다. 코드 예제에서는 두 개의 기본 클래스로 이루어져 있습니다.

  • EmployeeLogic 클래스는 비즈니스 논리를 캡슐화 하는 클래스입니다.

  • NorthwindEmployee 클래스를 로드 하 고 데이터 계층에서 데이터를 유지 하는 데 필요한 기본적인 기능만 포함 하는 모델 클래스입니다.

간단히 하기 위해는 EmployeeLogic 클래스는 데이터 계층에서 데이터를 검색 하는 것이 아니라 데이터의 정적 집합을 만듭니다. 필터링을 보여 주기 위해 Northwind Traders 직원의 전체 이름을 제공 하는 샘플을 실행 하기 때문에 예를 들어도 유용 합니다. 전체 작업 예제를 컴파일 및 제공 되는 Web Forms 코드 예제를 사용 하 여 이러한 클래스를 사용 해야 합니다.

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;  }
    }    
  }
}
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


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
   
   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
End Namespace

설명

ObjectDataSource 컨트롤 데이터 필터링을 지원 경우에만 Select 메서드가 반환 되는 DataSet 또는 DataTable 개체입니다.

이 구문에 사용되는 FilterExpression 구문은 형식 문자열 스타일 식입니다. 필터 식 구문은에 허용 되는 동일한 구문을 Expression 속성입니다. 매개 변수를 추가 하는 경우는 FilterParameters 컬렉션 형식 문자열 자리 표시자를 포함할 수도 있습니다. 예를 들어 "{0}" 식 매개 변수 값으로 대체 합니다. 매개 변수의 인덱스에 따라 자리 표시자는는 FilterParameters 컬렉션입니다.

매개 변수는 FilterExpression 속성입니다. 매개 변수 문자열 또는 문자 형식이 면 매개 변수를 작은따옴표로 묶습니다. 매개 변수가 숫자 형식인 경우에 따옴표 필요 하지 않습니다.

FilterParameters 속성 검색을 FilterParameters 속성에 포함 된를 ObjectDataSourceView 연관 된 개체는 ObjectDataSource 컨트롤.

적용 대상

추가 정보