ObjectDataSourceView.UpdateMethod Property
Assembly: System.Web (in system.web.dll)
/** @property */ public String get_UpdateMethod () /** @property */ public void set_UpdateMethod (String value)
public function get UpdateMethod () : String public function set UpdateMethod (value : String)
Property Value
A string that represents the name of the method or function that the ObjectDataSourceView uses to update data. The default is an empty string ("").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.
The method can be an instance method or a static (Shared in Visual Basic) method. If it is an instance method, the business object is created and destroyed each time the method specified by the UpdateMethod property is called. You can handle the ObjectCreated event to work with the business object before the method specified by the UpdateMethod property is called. You can also handle the ObjectDisposing event that is raised after the UpdateMethod method is called. (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.
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. 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.
For more information, see ObjectDataSource.UpdateMethod.
The value of the UpdateMethod property is stored in view state.
The following code example demonstrates how to use a DropDownList control, TextBox controls, and several ObjectDataSource controls to update data. The DropDownList displays the name of a NorthwindEmployee, while the TextBox controls are used to enter and update address information. 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.JSL" Assembly="Samples.AspNet.JSL" %>
<%@ Page language="VJ#" %>
<%@ Import namespace="Samples.AspNet.JSL" %>
<Script runat="server">
// Add parameters and initialize the user interface
// only if an employee is selected.
private void Page_Load(Object sender, EventArgs e) throws NorthwindDataException
{
// Be sure the text boxes are initialized with
// data from the currently selected employee.
NorthwindEmployee selectedEmployee =
EmployeeLogic.GetEmployee(DropDownList1.get_SelectedValue());
if (selectedEmployee != null) {
AddressBox.set_Text(selectedEmployee.get_Address());
CityBox.set_Text(selectedEmployee.get_City());
PostalCodeBox.set_Text(selectedEmployee.get_PostalCode());
Button1.set_Enabled(true);
}
else {
Button1.set_Enabled(false);
}
} //Page_Load
// Press the button to update.
private void Btn_UpdateEmployee(Object sender, CommandEventArgs e)
{
ObjectDataSource2.Update();
} //Btn_UpdateEmployee
</Script>
<html>
<head>
<title>ObjectDataSource - VJ# 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.JSL.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. -->
<asp:objectdatasource
id="ObjectDataSource2"
runat="server"
updatemethod="UpdateEmployeeWrapper"
typename="Samples.AspNet.JSL.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>
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.