ObjectDataSourceFilteringEventArgs ObjectDataSourceFilteringEventArgs ObjectDataSourceFilteringEventArgs ObjectDataSourceFilteringEventArgs Class

정의

Filtering 컨트롤의 ObjectDataSource 이벤트에 대한 데이터를 제공합니다.Provides data for the Filtering event of the ObjectDataSource control.

public ref class ObjectDataSourceFilteringEventArgs : System::ComponentModel::CancelEventArgs
public class ObjectDataSourceFilteringEventArgs : System.ComponentModel.CancelEventArgs
type ObjectDataSourceFilteringEventArgs = class
    inherit CancelEventArgs
Public Class ObjectDataSourceFilteringEventArgs
Inherits CancelEventArgs
상속
ObjectDataSourceFilteringEventArgsObjectDataSourceFilteringEventArgsObjectDataSourceFilteringEventArgsObjectDataSourceFilteringEventArgs

예제

이 섹션에는 두 코드 예제가 있습니다.This section contains two code examples. 첫 번째 코드 예제를 사용 하 여 필터링 된 데이터를 표시 하는 방법에 설명를 ObjectDataSource 중간 계층 비즈니스 개체에서 데이터를 검색 컨트롤을 사용 하 여 다음을 GridView 결과 표시 하는 컨트롤입니다.The first code example demonstrates how to display filtered data by using an ObjectDataSource control to retrieve data from a middle-tier business object, and then using a GridView control to display the results. 두 번째 코드 예제에서는 첫 번째 코드 예제에서 사용 되는 중간 계층 비즈니스 개체의 예제를 제공 합니다.The second code example provides an example of a middle-tier business object that is used by the first code example.

다음 코드 예제에 사용 하 여 필터링 된 데이터를 표시 하는 방법을 보여 줍니다.는 ObjectDataSource 컨트롤을 중간 계층 비즈니스 개체에서 데이터를 검색 하 고 사용 하 여를 GridView 결과 표시 하는 컨트롤입니다.The following code example demonstrates how to display filtered data by using an ObjectDataSource control to retrieve data from a middle-tier business object, and then using a GridView control to display the results. 합니다 ObjectDataSource 제어로 데이터를 검색 하는 메서드를 검색 하는 경우에 데이터를 필터링 할 수는 DataSet 또는 DataTable 개체입니다.The ObjectDataSource control can filter data only when the method that retrieves the data retrieves it as a DataSet or DataTable object. 이러한 이유로 합니다 SelectMethod 데이터를 검색 하는 비즈니스 개체 메서드를 식별 하는 속성을 DataSet 또는 DataTable 개체.For this reason, the SelectMethod property identifies a business object method that retrieves data as a DataSet or DataTable object.

코드 예제에서는 구성를 TextBox 컨트롤을 GridView 컨트롤을 ObjectDataSource 컨트롤 및 제출 단추.The code example consists of a TextBox control, a GridView control, the ObjectDataSource control, and a Submit button. 기본적으로 TextBox 컨트롤이 Northwind traders 직원 중 하나의 이름으로 채워집니다.By default, the TextBox control is populated with the name of one of the employees at Northwind Traders. 합니다 GridView 컨트롤의 이름으로 식별 되는 직원에 대 한 정보를 표시 합니다 TextBox합니다.The GridView control displays information about the employee who is identified by the name in the TextBox. 다른 직원에 대 한 데이터를 검색 하는 TextBox 제어를 해당 직원의 전체 이름을 입력 한 다음 클릭 합니다 제출 단추.To retrieve data for another employee, in the TextBox control, type the full name of the employee, and then click the Submit button.

합니다 FilterExpression 속성에 지정 된 메서드에 의해 검색 되는 데이터를 필터링 하는 데 사용 되는 식을 지정 합니다 SelectMethod 속성입니다.The FilterExpression property specifies an expression that is used to filter the data that is retrieved by the method that is specified by the SelectMethod property. 에 포함 된 매개 변수를 계산 되는 매개 변수 자리 표시자를 사용 합니다 FilterParameters 컬렉션입니다.It uses parameter placeholders that are evaluated to the parameters that are contained in the FilterParameters collection. 이 예제에서는 이러한 매개 변수 자리 표시자는 공백을 포함할 수 있는 문자열 형식 매개 변수 형식의 작은따옴표 (')으로 묶입니다.In this example, the parameter placeholder is enclosed by single quotation marks (') because the type of the parameter is a string type that might contain spaces. 매개 변수 형식의 숫자 또는 날짜 이면 따옴표 필요 하지 않습니다.If the type of the parameter is numeric or date, quotation marks are not required. FilterParameters 하나의 매개 변수를 포함 하는 컬렉션을 FormParameter 바인딩되는 개체는 TextBox 컨트롤입니다.The FilterParameters collection contains one parameter, a FormParameter object that is bound to the TextBox control.

에 지정 된 이름이 없는 경우는 TextBox 컨트롤을 새 매개 변수는 추가 ParameterValues 컬렉션 검색에 성공 하 합니다.If no name is specified in the TextBox control, a new parameter is added to the ParameterValues collection so that the search is successful.

중요

이 예제에서는 잠재적 보안 위협을 사용자 입력을 허용 하는 텍스트 상자가 포함 되어 있습니다.This example contains a text box that accepts user input, which is a potential security threat. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다.By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 자세한 내용은 Script Exploits Overview를 참조하세요.For more information, see Script Exploits Overview.

<%@ 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>

다음 코드 예제에서는 앞의 코드 예제를 사용 하는 중간 계층 비즈니스 개체의 예제를 제공 합니다.The following code example provides an example of a middle-tier business object that the preceding code example uses. 코드 예제에서는 기본 클래스로 구성 됩니다. EmployeeLogicNorthwindEmployee입니다.The code example consists of two basic classes: EmployeeLogic and NorthwindEmployee. 합니다 EmployeeLogic 비즈니스 논리를 캡슐화 하는 클래스 및 NorthwindEmployee 클래스는 로드 하 고 데이터 계층에서 데이터를 유지 하는 데 필요한 기본적인 기능만 포함 하는 모델 클래스입니다.The EmployeeLogic class encapsulates business logic and the NorthwindEmployee class is a model class that contains only the basic functionality that is required to load and persist data from the data tier. 간단히 하기 위해는 EmployeeLogic 클래스는 데이터 계층에서 데이터를 검색 하는 것이 아니라 데이터의 정적 집합을 만듭니다.For simplicity, the EmployeeLogic class creates a static set of data, rather than retrieving the data from a data tier. 전체 작업 예제를 컴파일 및 제공 되는 Web Forms 코드 예제를 사용 하 여 이러한 클래스를 사용 해야 합니다.For a complete working example, you must compile and use these classes with the Web Forms code examples that are provided.

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

설명

ObjectDataSourceFilteringEventArgs 클래스에 데이터를 전달 하는 데 사용 됩니다 합니다 Filtering 이벤트 처리기는 ObjectDataSource 컨트롤입니다.The ObjectDataSourceFilteringEventArgs class is used to pass data to the Filtering event handler of the ObjectDataSource control. ParameterValues 필터링 작업을 수행 하기 전에 속성은 필터 매개 변수 값에 대 한 액세스를 제공 합니다.The ParameterValues property provides access to the filter parameter values before the filtering operation is performed. 취소할 수 있습니다는 Select 설정 하 여 메서드를 Cancel 의 속성을 ObjectDataSourceFilteringEventArgstrue.You can cancel the Select method by setting the Cancel property of the ObjectDataSourceFilteringEventArgs to true.

생성자

ObjectDataSourceFilteringEventArgs(IOrderedDictionary) ObjectDataSourceFilteringEventArgs(IOrderedDictionary) ObjectDataSourceFilteringEventArgs(IOrderedDictionary) ObjectDataSourceFilteringEventArgs(IOrderedDictionary)

지정된 개체를 사용하여 ObjectDataSourceFilteringEventArgs 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the ObjectDataSourceFilteringEventArgs class by using the specified object.

속성

Cancel Cancel Cancel Cancel

이벤트를 취소해야 할지 여부를 나타내는 값을 가져오거나 설정합니다.Gets or sets a value indicating whether the event should be canceled.

(Inherited from CancelEventArgs)
ParameterValues ParameterValues ParameterValues ParameterValues

ObjectDataSource 클래스의 Parameter 개체에 액세스할 수 있는 IOrderedDictionary 인터페이스를 가져옵니다.Gets an IOrderedDictionary interface that provides access to the Parameter objects of the ObjectDataSource class.

메서드

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

기본 해시 함수로 작동합니다.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object.

(Inherited from Object)

적용 대상

추가 정보