ObjectDataSourceView.OnDeleting(ObjectDataSourceMethodEventArgs) ObjectDataSourceView.OnDeleting(ObjectDataSourceMethodEventArgs) ObjectDataSourceView.OnDeleting(ObjectDataSourceMethodEventArgs) ObjectDataSourceView.OnDeleting(ObjectDataSourceMethodEventArgs) Method

정의

Deleting 개체가 삭제 작업을 시도하기 전에 ObjectDataSourceView 이벤트를 발생시킵니다.Raises the Deleting event before the ObjectDataSourceView object attempts a delete operation.

protected:
 virtual void OnDeleting(System::Web::UI::WebControls::ObjectDataSourceMethodEventArgs ^ e);
protected virtual void OnDeleting (System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs e);
abstract member OnDeleting : System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs -> unit
override this.OnDeleting : System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs -> unit
Protected Overridable Sub OnDeleting (e As ObjectDataSourceMethodEventArgs)

매개 변수

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다.는 ObjectDataSource 비즈니스 개체를 사용 하 여 컨트롤 및 GridView 컨트롤 데이터를 삭제 합니다.The following code example demonstrates how to use an ObjectDataSource control with a business object and a GridView control to delete data. GridView 처음에 지정 된 메서드를 사용 하 여 모든 직원의 집합을 표시 합니다 SelectMethod 속성에서 데이터를 검색 하는 EmployeeLogic 개체.The GridView initially displays a set of all employees, using the method that is specified by the SelectMethod property to retrieve the data from the EmployeeLogic object. 때문에 AutoGenerateDeleteButton 속성이 trueGridView 컨트롤이 자동으로 표시를 삭제 단추입니다.Because the AutoGenerateDeleteButton property is set to true, the GridView control automatically displays a Delete button.

클릭 하면를 삭제 단추를를 Delete 작업이 수행 하 여 지정 된 메서드를 사용 하는 DeleteMethod 속성 및 지정 된 매개 변수는 DeleteParameters 컬렉션.If you click the Delete button, the Delete operation is performed using the method that is specified by the DeleteMethod property and any parameters that are specified in the DeleteParameters collection. 이 코드 예제에서는 몇 가지 전처리 및 후 처리 단계도 수행 됩니다.In this code example, some preprocessing and post-processing steps are also performed. NorthwindEmployeeDeleting 대리자를 처리 하기 위해 호출 됩니다는 Deleting 되기 전, 이벤트를 Delete 작업을 수행 및 NorthwindEmployeeDeleted 대리자를 처리 하기 위해 호출 됩니다는 Deleted 후 이벤트를 Delete 에 작업이 완료 되 예외 처리를 수행 합니다.The NorthwindEmployeeDeleting delegate is called to handle the Deleting event before the Delete operation is performed, and the NorthwindEmployeeDeleted delegate is called to handle the Deleted event after the Delete operation has completed, to perform an exception handling. 이 예제의 경우는 NorthwindDataException 는이 대리자에 의해 처리 됩니다 throw 합니다.In this example, if a NorthwindDataException is thrown, it is handled by this delegate.

구현을 확인 하는 EmployeeLogic 이 코드 예제는 중간 계층 비즈니스 개체 참조 ObjectDataSourceStatusEventArgs합니다.To examine the implementation of the EmployeeLogic middle-tier business object that this code example uses, see ObjectDataSourceStatusEventArgs.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %>
<%@ 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 NorthwindEmployeeDeleting(object source, ObjectDataSourceMethodEventArgs e)
{
  // The GridView passes the ID of the employee
  // to be deleted. However, the buisiness object, EmployeeLogic,
  // requires a NorthwindEmployee parameter, named "ne". Create
  // it now and add it to the parameters collection.
  IDictionary paramsFromPage = e.InputParameters;
  if (paramsFromPage["EmpID"] != null) {
    NorthwindEmployee ne
      = new NorthwindEmployee( Int32.Parse(paramsFromPage["EmpID"].ToString()));
    // Remove the old EmpID parameter.
    paramsFromPage.Clear();
    paramsFromPage.Add("ne", ne);
  }
}

private void NorthwindEmployeeDeleted(object source, ObjectDataSourceStatusEventArgs e)
{
  // Handle the Exception if it is a NorthwindDataException
  if (e.Exception != null)
  {

    // Handle the specific exception type. The ObjectDataSource wraps
    // any Exceptions in a TargetInvokationException wrapper, so
    // check the InnerException property for expected Exception types.
    if (e.Exception.InnerException is NorthwindDataException)
    {
      Label1.Text = e.Exception.InnerException.Message;
      // Because the exception is handled, there is
      // no reason to throw it.
      e.ExceptionHandled = true;
    }
  }
}

</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"
          autogeneratedeletebutton="true"
          autogeneratecolumns="false"
          datakeynames="EmpID">
          <columns>
            <asp:boundfield headertext="EmpID" datafield="EmpID" />
            <asp:boundfield headertext="First Name" datafield="FirstName" />
            <asp:boundfield headertext="Last Name" datafield="LastName" />
          </columns>
        </asp:gridview>

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetAllEmployees"
          deletemethod="DeleteEmployee"
          ondeleting="NorthwindEmployeeDeleting"
          ondeleted="NorthwindEmployeeDeleted"
          typename="Samples.AspNet.CS.EmployeeLogic">
          <deleteparameters>
            <asp:parameter name="EmpID" type="Int32" />
          </deleteparameters>
        </asp:objectdatasource>

        <asp:label id="Label1" runat="server" />

    </form>
  </body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB" Assembly="Samples.AspNet.VB" %>
<%@ 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">
' Called before a Delete operation.
    Private Sub NorthwindEmployeeDeleting(ByVal source As Object, ByVal e As ObjectDataSourceMethodEventArgs)

        ' The GridView passes the ID of the employee
        ' to be deleted. However, the business object, EmployeeLogic,
        ' requires a NorthwindEmployee parameter, named "ne". Create
        ' it now and add it to the parameters collection.
        Dim paramsFromPage As IDictionary = e.InputParameters
  
        If Not paramsFromPage("EmpID") Is Nothing Then
    
            Dim ne As New NorthwindEmployee(paramsFromPage("EmpID").ToString())
            ' Remove the old EmpID parameter.
            paramsFromPage.Clear()
            paramsFromPage.Add("ne", ne)
    
    
        End If
    End Sub ' NorthwindEmployeeDeleting

    ' Called after a Delete operation.
    Private Sub NorthwindEmployeeDeleted(ByVal source As Object, ByVal e As ObjectDataSourceStatusEventArgs)
        ' Handle the Exception if it is a NorthwindDataException.
        If Not e.Exception Is Nothing Then

            ' Handle the specific exception type. The ObjectDataSource wraps
            ' any Exceptions in a TargetInvokationException wrapper, so
            ' check the InnerException property for the expected Exception types.
            If e.Exception.InnerException.GetType().Equals(GetType(NorthwindDataException)) Then

                Label1.Text = e.Exception.InnerException.Message
                ' Because the exception is handled, there is
                ' no reason to throw it.
                e.ExceptionHandled = True
      
            End If
        End If
    End Sub ' NorthwindEmployeeDeleted
</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"
          autogeneratedeletebutton="true"
          autogeneratecolumns="false"
          datakeynames="EmpID">
          <columns>
            <asp:boundfield headertext="EmpID" datafield="EmpID" />
            <asp:boundfield headertext="First Name" datafield="FirstName" />
            <asp:boundfield headertext="Last Name" datafield="LastName" />
          </columns>
        </asp:gridview>

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetAllEmployees"
          deletemethod="DeleteEmployee"
          ondeleting="NorthwindEmployeeDeleting"
          ondeleted="NorthwindEmployeeDeleted"
          typename="Samples.AspNet.VB.EmployeeLogic">
          <deleteparameters>
            <asp:parameter name="EmpID" type="Int32" />
          </deleteparameters>
        </asp:objectdatasource>

        <asp:label id="Label1" runat="server" />

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

설명

이벤트가 발생하면 대리자를 통해 이벤트 처리기가 호출됩니다.Raising an event invokes the event handler through a delegate. 이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.For more information about how to handle events, see Handling and Raising Events.

또한 OnDeleting 메서드를 사용하면 파생 클래스가 대리자를 연결하지 않고도 이벤트를 처리할 수 있습니다.The OnDeleting method also allows derived classes to handle the event without attaching a delegate. 이는 파생 클래스에서 이벤트를 처리하는 기본 방법입니다.This is the preferred technique for handling the event in a derived class.

상속자 참고

재정의 하는 경우는 OnDeleting(ObjectDataSourceMethodEventArgs) 파생된 클래스에서 메서드를 호출 해야 합니다 OnDeleting(ObjectDataSourceMethodEventArgs) 대리자를 등록 하는 기본 클래스의 메서드는 이벤트를 받도록 합니다.When overriding the OnDeleting(ObjectDataSourceMethodEventArgs) method in a derived class, be sure to call the OnDeleting(ObjectDataSourceMethodEventArgs) method for the base class so that registered delegates receive the event.

적용 대상

추가 정보