This documentation is archived and is not being maintained.

ObjectDataSourceView.Updating Event

Occurs before an Update operation.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public event ObjectDataSourceMethodEventHandler Updating

Handle the Updating event to perform additional initialization operations that are specific to your application, to validate the values of parameters, or to change the parameter values before the ObjectDataSource control performs the Update operation. The parameters are available as an IDictionary collection, accessed by the InputParameters property, which is exposed by the ObjectDataSourceMethodEventArgs object.

For more information about handling events, see Consuming Events.

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.CS" Assembly="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<%@ Import namespace="Samples.AspNet.CS" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<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) {

// Dynamically add parameters to the InputParameters collection. 
private void NorthwindEmployeeUpdating(object source, ObjectDataSourceMethodEventArgs e) {

  // The names of the parameters are the same as 
  // the variable names for the method that is invoked to 
  // perform the Update. The InputParameters collection is 
  // an IDictionary collection of name/value pairs, 
  // not a ParameterCollection.
  e.InputParameters.Add("anID",       DropDownList1.SelectedValue);
  e.InputParameters.Add("anAddress"  ,AddressBox.Text);
  e.InputParameters.Add("aCity"      ,CityBox.Text);
<html xmlns="" >
    <title>ObjectDataSource - C# Example</title>
    <form id="Form1" method="post" runat="server">

        <!-- The DropDownList is bound to the first ObjectDataSource. -->
          typename="Samples.AspNet.CS.EmployeeLogic" />

          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. -->

          typename="Samples.AspNet.CS.EmployeeLogic" />

          runat="server" /></p>

          runat="server" /></p>

          runat="server" /></p>

          text="Update Employee"
          oncommand="Btn_UpdateEmployee" />


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0