ObjectDataSourceView.DeleteMethod 속성

정의

ObjectDataSourceView 개체가 데이터를 삭제할 때 호출하는 메서드나 함수의 이름을 가져오거나 설정합니다.

public:
 property System::String ^ DeleteMethod { System::String ^ get(); void set(System::String ^ value); };
public string DeleteMethod { get; set; }
member this.DeleteMethod : string with get, set
Public Property DeleteMethod As String

속성 값

ObjectDataSourceView에서 데이터를 삭제할 때 사용하는 메서드나 함수의 이름을 나타내는 문자열입니다. 기본값은 빈 문자열("")입니다.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다.는 ObjectDataSource 비즈니스 개체를 사용 하 여 컨트롤 및 GridView 컨트롤 데이터를 삭제 합니다. GridView 처음에 지정 된 메서드를 사용 하 여 모든 직원의 집합을 표시 합니다 SelectMethod 속성에서 데이터를 검색 하는 EmployeeLogic 개체. 때문에 AutoGenerateDeleteButton 속성이 trueGridView 컨트롤이 자동으로 표시를 삭제 단추입니다.

클릭 하면를 삭제 단추를를 Delete 작업이 수행 하 여 지정 된 메서드를 사용 하는 DeleteMethod 속성 및 지정 된 매개 변수는 DeleteParameters 컬렉션. 이 코드 예제에서는 몇 가지 전처리 및 후 처리 단계도 수행 됩니다. NorthwindEmployeeDeleting 대리자를 처리 하기 위해 호출 됩니다는 Deleting 되기 전, 이벤트를 Delete 작업을 수행 및 NorthwindEmployeeDeleted 대리자를 처리 하기 위해 호출 됩니다는 Deleted 후 이벤트를 Delete 에 작업이 완료 되 예외 처리를 수행 합니다. 이 예제의 경우는 NorthwindDataException 는이 대리자에 의해 처리 됩니다 throw 합니다.

구현을 확인 하는 EmployeeLogic 이 코드 예제는 중간 계층 비즈니스 개체 참조 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>

설명

로 식별 되는 메서드를 DeleteMethod 속성에는 인스턴스 메서드 일 수 있습니다 또는 static (Shared Visual Basic에서) 메서드. 인스턴스 메서드인 경우 비즈니스 개체가 만들어지고 소멸 될 때마다 지정 된 메서드는 DeleteMethod 속성 이라고 합니다. 처리할 수 있습니다 합니다 ObjectCreated 지정 된 메서드 앞에 비즈니스 개체를 사용 하는 이벤트를 DeleteMethod 속성 이라고 합니다. 처리할 수도 있습니다는 ObjectDisposing 으로 지정한 메서드의 후 발생 하는 이벤트를 DeleteMethod 속성 이라고 합니다. 메서드인 경우는 static (Shared Visual Basic에서) 메서드를 비즈니스 개체가 생성 되지 않고 이러한 이벤트를 처리할 수 없습니다.

비즈니스 개체는 경우는 ObjectDataSource 둘 이상의 메서드 또는 함수 (메서드 오버 로드) 이름이 같은 컨트롤 구현 작동, 데이터 소스 컨트롤의 올바른 매개 변수를 포함 한 조건 집합에 따라 호출 하려고 합니다. 에 DeleteParameters 컬렉션입니다. 경우에 매개 변수를 DeleteParameters 컬렉션의 정의와 일치 하지 않습니다는 DeleteMethod 메서드 시그니처를 데이터 원본에는 예외가 throw 됩니다.

값을 DeleteMethod 속성은 뷰 상태에 저장 됩니다.

자세한 내용은 DeleteMethod를 참조하세요.

적용 대상

추가 정보