ObjectDataSourceMethodEventArgs.InputParameters Property


Gets a collection that contains business object method parameters and their values.

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

public IOrderedDictionary InputParameters { get; }

Property Value

Type: System.Collections.Specialized.IOrderedDictionary

An IDictionary of name/value pairs that represent the business object method parameters and their corresponding values.

Parameters can be passed to the business object method by reference or by value. If you use an ObjectDataSourceMethodEventHandler object to handle the Selecting, Updating, Inserting, or Deleting events, you can access and manipulate these parameters using the InputParameters property. Any changes to the parameters in this dictionary will affect which method overload is called for the operation. When the DataObjectTypeName property of the ObjectDataSource control is set, you can modify only the data object properties for the items in this dictionary; you cannot add or remove parameters. For more information, see Delete.

Parameters that are passed by reference are returned in the OutputParameters property of the ObjectDataSourceStatusEventArgs object.

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 Northwind Employee, while the TextBox controls are used to enter and update address information. Because the UpdateParameters property contains a ControlParameter object that is bound to the selected value of the DropDownList control, the button that triggers the Update method is only enabled after an employee is selected.

In this example, the NorthwindEmployeeUpdating method is called before the Update method to add the correct parameters and values to the InputParameters collection. You can add the parameters and values dynamically, as demonstrated, or declaratively.

<%@ 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="http://www.w3.org/1999/xhtml" >
    <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" />


.NET Framework
Available since 2.0
Return to top