Esta documentación está archivada y no tiene mantenimiento.

ObjectDataSourceMethodEventArgs.InputParameters (Propiedad)

Obtiene una colección que contiene parámetros del método de objeto comercial y sus valores.

Espacio de nombres: System.Web.UI.WebControls
Ensamblado: System.Web (en system.web.dll)

public IOrderedDictionary InputParameters { get; }
/** @property */
public IOrderedDictionary get_InputParameters ()

public function get InputParameters () : IOrderedDictionary

No aplicable.

Valor de propiedad

Un objeto IDictionary de pares nombre/valor que representan los parámetros del método de objeto comercial y sus valores correspondientes.

Los parámetros se pueden pasar por referencia o por valor al método de objeto comercial. Si utiliza un objeto ObjectDataSourceMethodEventHandler para controlar los eventos Selecting, Updating, Inserting o Deleting, puede obtener acceso a estos parámetros y manipularlos por medio de la propiedad InputParameters. Cualquier cambio de los parámetros de este diccionario afectará a la sobrecarga de método que se llama para la operación. Si se establece la propiedad DataObjectTypeName del control ObjectDataSource, sólo se pueden modificar las propiedades del objeto de datos de los elementos de este diccionario; no se pueden agregar ni quitar parámetros. Para obtener más información, vea Delete.

Los parámetros que se pasan por referencia se devuelven en la propiedad OutputParameters del objeto ObjectDataSourceStatusEventArgs.

En el ejemplo de código siguiente se muestra cómo se utiliza un control DropDownList, los controles TextBox y varios controles ObjectDataSource para actualizar datos. El objeto DropDownList muestra el nombre de un empleado de Northwind, mientras que los controles TextBox se utilizan para escribir y actualizar información de dirección. Dado que la propiedad UpdateParameters contiene un objeto ControlParameter enlazado al valor seleccionado del control DropDownList, el botón que inicia el método Update sólo está habilitado después de seleccionar un empleado.

En este ejemplo, se llama al método NorthwindEmployeeUpdating antes del método Update para agregar los parámetros y valores correctos a la colección InputParameters. Puede agregar los parámetros y valores dinámicamente, como se muestra, o mediante declaración.

<%@ 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();
}

// 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);
  e.InputParameters.Add("aPostalCode",PostalCodeBox.Text);
}
</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. -->

        <asp:objectdatasource
          id="ObjectDataSource2"
          runat="server"
          updatemethod="UpdateEmployeeWrapper"
          onupdating="NorthwindEmployeeUpdating"
          typename="Samples.AspNet.CS.EmployeeLogic" />

        <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.JSL" Assembly="Samples.AspNet.JSL" %>
<%@ Page Language="VJ#" %>
<%@ Import namespace="Samples.AspNet.JSL" %>
<!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, System.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


    // 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.get_InputParameters().Add("anID", DropDownList1.get_SelectedValue());
        e.get_InputParameters().Add("anAddress", AddressBox.get_Text());
        e.get_InputParameters().Add("aCity", CityBox.get_Text());
        e.get_InputParameters().Add("aPostalCode", PostalCodeBox.get_Text());
    } //NorthwindEmployeeUpdating
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <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"
          onupdating="NorthwindEmployeeUpdating"
          typename="Samples.AspNet.JSL.EmployeeLogic" />

        <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 Service Pack 4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter

Microsoft .NET Framework 3.0 es compatible con Windows Vista, Microsoft Windows XP SP2 y Windows Server 2003 SP1.

.NET Framework

Compatible con: 3.0, 2.0
Mostrar: