ObjectDataSourceObjectEventHandler 대리자

정의

ObjectCreating 컨트롤의 ObjectCreatedObjectDataSource 이벤트를 처리할 메서드를 나타냅니다.Represents the method that will handle the ObjectCreating and ObjectCreated events of the ObjectDataSource control.

public delegate void ObjectDataSourceObjectEventHandler(System::Object ^ sender, ObjectDataSourceEventArgs ^ e);
public delegate void ObjectDataSourceObjectEventHandler(object sender, ObjectDataSourceEventArgs e);
type ObjectDataSourceObjectEventHandler = delegate of obj * ObjectDataSourceEventArgs -> unit
Public Delegate Sub ObjectDataSourceObjectEventHandler(sender As Object, e As ObjectDataSourceEventArgs)

매개 변수

sender
Object

이벤트 소스입니다.The source of the event.

e
ObjectDataSourceEventArgs

이벤트 데이터를 포함하는 ObjectDataSourceEventArgs입니다.An ObjectDataSourceEventArgs that contains the event data.

상속
ObjectDataSourceObjectEventHandler

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다.는 ObjectDataSource 비즈니스 개체를 사용 하 여 컨트롤 및 GridView 컨트롤을 검색 하 고 정보를 표시 합니다.The following code example demonstrates how to use an ObjectDataSource control with a business object and a GridView control to retrieve and display information. 많은 실제 시나리오와 마찬가지로이 예제에서는 하지 않을 수 또는 비즈니스 개체의 기본 인스턴스를 사용 하 여 ObjectDataSource 컨트롤입니다.In this example, as in many real-world scenarios, it might not be possible or appropriate to use a default instance of the business object with the ObjectDataSource control. 이 예제 ObjectDataSource 에서는가 예외를 throw 하기 때문에 매개 변수가 없는 생성자를 성공적으로 호출할 수 없습니다.In this example, the ObjectDataSource cannot successfully call the parameterless constructor because it will throw an exception. 일부 경우에는 매개 변수가 없는 생성자가 보호 될 수 있으며, 다른 생성자에서는 비즈니스 개체를 원하는 상태로 초기화 하지 못할 수 있습니다.In some cases, the parameterless constructor might be protected, and in others it might not initialize the business object to a desired state. 어떤 이유가 든 비즈니스를 인스턴스화할 수 있습니다 개체를 직접 및 인스턴스 설정 합니다 ObjectInstance 의 속성은 ObjectDataSourceEventArgs 처리기에 전달 되는 개체입니다.Whatever the reason, you can instantiate the business object yourself and set the instance to the ObjectInstance property of the ObjectDataSourceEventArgs object that is passed to the handler. 비즈니스 개체 인스턴스는 ObjectDataSource 작업 하는 데 사용 됩니다.This is the business object instance that the ObjectDataSource will use to perform its work.

<%@ Import namespace="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">
private void NorthwindLogicCreating(object sender, ObjectDataSourceEventArgs e)
{
    // Create an instance of the business object using a non-default constructor.
    EmployeeLogic eLogic = new EmployeeLogic("Not created by the default constructor!");
    
    // Set the ObjectInstance property so that the ObjectDataSource uses the created instance.
    e.ObjectInstance = eLogic;
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>ObjectDataSource - C# Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">

        <asp:gridview
          id="GridView1"
          runat="server"
          datasourceid="ObjectDataSource1">
        </asp:gridview>

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetAllEmployees"
          onobjectcreating="NorthwindLogicCreating"
          typename="Samples.AspNet.CS.EmployeeLogic" >
        </asp:objectdatasource>

    </form>
  </body>
</html>
<%@ Import namespace="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">
Private Sub NorthwindLogicCreating(sender As Object, e As ObjectDataSourceEventArgs)

    ' Create an instance of the business object using a non-default constructor.
    Dim eLogic As EmployeeLogic = New EmployeeLogic("Not created by the default constructor!")
    
    ' Set the ObjectInstance property so that the ObjectDataSource uses the created instance.
    e.ObjectInstance = eLogic
    
End Sub ' NorthwindLogicCreating

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>ObjectDataSource - VB Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">

        <asp:gridview
          id="GridView1"
          runat="server"
          datasourceid="ObjectDataSource1">
        </asp:gridview>

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetAllEmployees"
          onobjectcreating="NorthwindLogicCreating"
          typename="Samples.AspNet.VB.EmployeeLogic" >
        </asp:objectdatasource>

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

다음 코드 예제에서는 앞의 예제에서 사용 되는 예제에서는 기본 비즈니스 개체를 보여 줍니다.The following code example demonstrates the example basic business object used in the preceding example.

namespace Samples.AspNet.CS {

using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;

  public class EmployeeLogic {

    public EmployeeLogic() {  
        throw new NotSupportedException("Initialize data.");
    }
    
    public EmployeeLogic(string data) {
        _data = data;
    }

    private string _data;
    
    // Returns a collection of NorthwindEmployee objects.
    public ICollection GetAllEmployees () {
      ArrayList al = new ArrayList();      
      al.Add(_data);        
      return al;
    }
    
  }

}
Imports System.Collections
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace Samples.AspNet.VB
  Public Class EmployeeLogic
    
    
    Public Sub New() 
        Throw New NotSupportedException("Initialize data.")
    
    End Sub
    
    
    Public Sub New(ByVal data As String) 
        _data = data
    
    End Sub
    
    Private _data As String
    
    
    ' Returns a collection of NorthwindEmployee objects.
    Public Function GetAllEmployees() As ICollection 
        Dim al As New ArrayList()
        al.Add(_data)
        Return al
    
    End Function 'GetAllEmployees
  End Class
End Namespace ' Samples.AspNet.VB

설명

ObjectDataSourceObjectEventHandler 대리자를 만드는 경우 이벤트를 처리할 메서드를 결정합니다.When you create an ObjectDataSourceObjectEventHandler delegate, you identify the method that will handle the event. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 해당 이벤트에 추가합니다.To associate the event with your event handler, add an instance of the delegate to the event. 대리자를 제거하지 않는 경우 이벤트가 발생할 때마다 이벤트 처리기가 호출됩니다.The event handler is called whenever the event occurs, unless you remove the delegate. 이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.For more information about how to handle events, see Handling and Raising Events.

확장 메서드

GetMethodInfo(Delegate)

지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.Gets an object that represents the method represented by the specified delegate.

적용 대상

추가 정보