ObjectDataSourceView.UpdateMethod ObjectDataSourceView.UpdateMethod ObjectDataSourceView.UpdateMethod ObjectDataSourceView.UpdateMethod Property

Definizione

Ottiene o imposta il nome del metodo o funzione che l'oggetto ObjectDataSourceView richiama per aggiornare i dati.Gets or sets the name of the method or function that the ObjectDataSourceView object invokes to update data.

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

Valore della proprietà

Stringa che rappresenta il nome del metodo o funzione che l'oggetto ObjectDataSourceView utilizza per aggiornare i dati.A string that represents the name of the method or function that the ObjectDataSourceView uses to update data. Il valore predefinito è una stringa vuota ("").The default is an empty string ("").

Esempi

Nell'esempio di codice riportato di seguito viene illustrato DropDownList come utilizzare TextBox un controllo, controlli ObjectDataSource e diversi controlli per aggiornare i dati.The following code example demonstrates how to use a DropDownList control, TextBox controls, and several ObjectDataSource controls to update data. Consente di visualizzare il nome di NorthwindEmployeeun oggetto, TextBox mentre i controlli vengono utilizzati per immettere e aggiornare le informazioni sull'indirizzo. DropDownListThe DropDownList displays the name of a NorthwindEmployee, while the TextBox controls are used to enter and update address information. Poiché la UpdateParameters raccolta contiene un ControlParameter oggetto associato al valore selezionato di DropDownList, il pulsante che attiva l' Update operazione viene abilitato solo dopo la selezione di un dipendente.Because the UpdateParameters collection contains a ControlParameter object that is bound to the selected value of the DropDownList, the button that triggers the Update operation is enabled only after an employee is selected.

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

Commenti

L' ObjectDataSourceView oggetto presuppone che il metodo identificato UpdateMethod dalla proprietà esegua aggiornamenti uno alla volta, anziché in un batch.The ObjectDataSourceView object assumes that the method that is identified by the UpdateMethod property performs updates one at a time, rather than in a batch.

Il metodo può essere un metodo di istanza o static unShared metodo (in Visual Basic).The method can be an instance method or a static (Shared in Visual Basic) method. Se si tratta di un metodo di istanza, l'oggetto business viene creato ed eliminato ogni volta che viene chiamato UpdateMethod il metodo specificato dalla proprietà.If it is an instance method, the business object is created and destroyed each time the method specified by the UpdateMethod property is called. È possibile gestire l' ObjectCreated evento in modo che funzioni con l'oggetto business prima che venga chiamato UpdateMethod il metodo specificato dalla proprietà.You can handle the ObjectCreated event to work with the business object before the method specified by the UpdateMethod property is called. È anche possibile gestire l' ObjectDisposing evento generato dopo la chiamata del UpdateMethod metodo.You can also handle the ObjectDisposing event that is raised after the UpdateMethod method is called. viene chiamato, solo se l'oggetto business implementa l' IDisposable interfaccia.Dispose Se il metodo è un static metodoShared (in Visual Basic), l'oggetto business non viene mai creato e non è possibile gestire questi eventi.(Dispose is called, only if the business object implements the IDisposable interface.) If the method is a static (Shared in Visual Basic) method, the business object is never created and you cannot handle these events.

Se l'oggetto business utilizzato dall' ObjectDataSource oggetto implementa più di un metodo o funzione con lo stesso nome (overload del metodo), il controllo origine dati tenta di richiamare quello corretto in base a un set di condizioni, inclusi i parametri. UpdateParameters nella raccolta.If the business object that the ObjectDataSource object works with implements more than one method or function with the same name (method overloads), the data source control attempts to invoke the correct one according to a set of conditions, including the parameters in the UpdateParameters collection. Se i parametri nella UpdateParameters raccolta non corrispondono a quelli della firma del metodo specificato UpdateMethod dalla proprietà, l'origine dati genera un'eccezione.If the parameters in the UpdateParameters collection do not match those of the signature of the method specified by the UpdateMethod property, the data source throws an exception.

Per ulteriori informazioni, vedere ObjectDataSource.UpdateMethod.For more information, see ObjectDataSource.UpdateMethod.

Il valore della UpdateMethod proprietà viene archiviato nello stato di visualizzazione.The value of the UpdateMethod property is stored in view state.

Si applica a

Vedi anche