ObjectDataSourceView.UpdateMethod 속성

정의

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

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

속성 값

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

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다.는 DropDownList 제어 TextBox 컨트롤 및 여러 ObjectDataSource 컨트롤 데이터를 업데이트 합니다. DropDownList 의 이름을 표시 하는 NorthwindEmployee, 하는 동안는 TextBox 컨트롤은 입력 하 고 주소 정보를 업데이트 하는 데 사용 됩니다. 때문에 UpdateParameters 컬렉션에 포함를 ControlParameter 의 선택된 된 값에 바인딩되는 개체를 DropDownList, 트리거하는 단추는 Update 직원을 선택한 후에 작업을 사용 하도록 설정 합니다.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<%@ Import namespace="Samples.AspNet.CS" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

// Add parameters and initialize the user interface
// only if an employee is selected.
private void Page_Load(object sender, EventArgs e)
{
  // Be sure the text boxes are initialized with
  // data from the currently selected employee.
  NorthwindEmployee selectedEmployee = EmployeeLogic.GetEmployee(DropDownList1.SelectedValue);
  if (selectedEmployee != null) {
    AddressBox.Text    = selectedEmployee.Address;
    CityBox.Text       = selectedEmployee.City;
    PostalCodeBox.Text = selectedEmployee.PostalCode;

    Button1.Enabled = true;
  }
  else {
    Button1.Enabled = false;
  }
}

// Press the button to update.
private void Btn_UpdateEmployee (object sender, CommandEventArgs e) {
  ObjectDataSource2.Update();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>ObjectDataSource - C# Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">

        <!-- The DropDownList is bound to the first ObjectDataSource. -->
        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetAllEmployees"
          typename="Samples.AspNet.CS.EmployeeLogic" />

        <p><asp:dropdownlist
          id="DropDownList1"
          runat="server"
          datasourceid="ObjectDataSource1"
          datatextfield="FullName"
          datavaluefield="EmpID"
          autopostback="True" /></p>

        <!-- The second ObjectDataSource performs the Update. This
             preserves the state of the DropDownList, which otherwise
             would rebind when the DataSourceChanged event is
             raised as a result of an Update operation. -->

        <!-- Security Note: The ObjectDataSource uses a FormParameter,
             Security Note: which does not perform validation of input from the client.
             Security Note: To validate the value of the FormParameter,
             Security Note: handle the Updating event. -->

        <asp:objectdatasource
          id="ObjectDataSource2"
          runat="server"
          updatemethod="UpdateEmployeeWrapper"
          typename="Samples.AspNet.CS.EmployeeLogic">
          <updateparameters>
            <asp:controlparameter name="anID" controlid="DropDownList1" propertyname="SelectedValue" />
            <asp:formparameter name="anAddress" formfield="AddressBox" />
            <asp:formparameter name="aCity" formfield="CityBox" />
            <asp:formparameter name="aPostalCode" formfield="PostalCodeBox" />
          </updateparameters>
        </asp:objectdatasource>

        <p><asp:textbox
          id="AddressBox"
          runat="server" /></p>

        <p><asp:textbox
          id="CityBox"
          runat="server" /></p>

        <p><asp:textbox
          id="PostalCodeBox"
          runat="server" /></p>

        <asp:button
          id="Button1"
          runat="server"
          text="Update Employee"
          oncommand="Btn_UpdateEmployee" />

    </form>
  </body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB" Assembly="Samples.AspNet.VB" %>
<%@ Page language="vb" %>
<%@ Import namespace="Samples.AspNet.VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

' Add parameters and initialize the user interface
' only if an employee is selected.
Private Sub Page_Load(sender As Object, e As EventArgs)

  ' Be sure the text boxes are initialized with
  ' data from the currently selected employee.
  Dim selectedEmployee As NorthwindEmployee
  selectedEmployee = EmployeeLogic.GetEmployee(DropDownList1.SelectedValue)

  If Not selectedEmployee Is Nothing Then
    AddressBox.Text    = selectedEmployee.Address
    CityBox.Text       = selectedEmployee.City
    PostalCodeBox.Text = selectedEmployee.PostalCode

    Button1.Enabled = True
  Else
    Button1.Enabled = False
  End If
End Sub ' Page_Load

' Press the button to update.
Private Sub Btn_UpdateEmployee (sender As Object, e As CommandEventArgs )
  ObjectDataSource2.Update()
End Sub ' Btn_UpdateEmployee

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

        <!-- The DropDownList is bound to the first ObjectDataSource. -->
        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetAllEmployees"
          typename="Samples.AspNet.VB.EmployeeLogic" />

        <p><asp:dropdownlist
          id="DropDownList1"
          runat="server"
          datasourceid="ObjectDataSource1"
          datatextfield="FullName"
          datavaluefield="EmpID"
          autopostback="True" /></p>

        <!-- The second ObjectDataSource performs the Update. This
             preserves the state of the DropDownList, which otherwise
             would rebind when the DataSourceChanged event is
             raised as a result of an Update operation. -->

        <!-- Security Note: The ObjectDataSource uses a FormParameter,
             Security Note: which does not perform validation of input from the client.
             Security Note: To validate the value of the FormParameter,
             Security Note: handle the Updating event. -->

        <asp:objectdatasource
          id="ObjectDataSource2"
          runat="server"
          updatemethod="UpdateEmployeeWrapper"
          typename="Samples.AspNet.VB.EmployeeLogic">
          <updateparameters>
            <asp:controlparameter name="anID" controlid="DropDownList1" propertyname="SelectedValue" />
            <asp:formparameter name="anAddress" formfield="AddressBox" />
            <asp:formparameter name="aCity" formfield="CityBox" />
            <asp:formparameter name="aPostalCode" formfield="PostalCodeBox" />
          </updateparameters>
        </asp:objectdatasource>

        <p><asp:textbox
          id="AddressBox"
          runat="server" /></p>

        <p><asp:textbox
          id="CityBox"
          runat="server" /></p>

        <p><asp:textbox
          id="PostalCodeBox"
          runat="server" /></p>

        <asp:button
          id="Button1"
          runat="server"
          text="Update Employee"
          oncommand="Btn_UpdateEmployee" />

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

설명

합니다 ObjectDataSourceView 가정 개체로 식별 되는 메서드는 UpdateMethod 속성 일괄 처리 대신 한 번에 한 업데이트를 수행 합니다.

메서드는 인스턴스 메서드 일 수 또는 static (Shared Visual Basic에서) 메서드. 인스턴스 메서드인 경우 비즈니스 개체가 만들어지고 소멸 될 때마다 지정 된 메서드는 UpdateMethod 속성 이라고 합니다. 처리할 수 있습니다 합니다 ObjectCreated 지정 된 메서드 앞에 비즈니스 개체를 사용 하는 이벤트를 UpdateMethod 속성 이라고 합니다. 처리할 수도 있습니다는 ObjectDisposing 후 발생 하는 이벤트를 UpdateMethod 메서드가 호출 됩니다. (Dispose 비즈니스 개체를 구현 하는 경우에 호출 되는 IDisposable 인터페이스입니다.) 메서드인 경우는 static (Shared Visual Basic에서) 메서드를 비즈니스 개체가 생성 되지 않고 이러한 이벤트를 처리할 수 없습니다.

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

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

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

적용 대상

추가 정보