ObjectDataSourceMethodEventArgs.InputParameters Özellik

Tanım

İş nesnesi yöntemi parametrelerini ve değerlerini içeren bir koleksiyon alır.

C#
public System.Collections.Specialized.IOrderedDictionary InputParameters { get; }

Özellik Değeri

IDictionary İş nesnesi yöntemi parametrelerini ve karşılık gelen değerlerini temsil eden ad/değer çiftlerinden biri.

Örnekler

Aşağıdaki kod örneği, verileri güncelleştirmek için bir DropDownList denetimin, TextBox denetimlerin ve çeşitli ObjectDataSource denetimlerin nasıl kullanılacağını gösterir. , DropDownList Bir Northwind Çalışanının adını görüntülerken TextBox , denetimler adres bilgilerini girmek ve güncelleştirmek için kullanılır. özelliği denetimin UpdateParameters seçili değerine bağlı bir ControlParameter nesne içerdiğinden DropDownList , yöntemi tetikleyen Update düğme yalnızca bir çalışan seçildikten sonra etkinleştirilir.

Bu örnekte yöntemi, NorthwindEmployeeUpdating koleksiyona doğru parametreleri ve değerleri eklemek için yönteminden önce Update çağrılır InputParameters . Parametreleri ve değerleri gösterildiği gibi dinamik olarak veya bildirim temelli olarak ekleyebilirsiniz.

ASP.NET (C#)
<%@ 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>

Açıklamalar

Parametreler iş nesnesi yöntemine başvuru veya değere göre geçirilebilir. , , InsertingUpdatingveya Deleting olaylarını işlemek Selectingiçin bir ObjectDataSourceMethodEventHandler nesne kullanırsanız, özelliğini kullanarak InputParameters bu parametrelere erişebilir ve bunları işleyebilirsiniz. Bu sözlükteki parametrelerde yapılan değişiklikler, işlem için hangi yöntem aşırı yüklemesinin çağrıldığını etkiler. Denetimin DataObjectTypeNameObjectDataSource özelliği ayarlandığında, bu sözlükteki öğelerin yalnızca veri nesnesi özelliklerini değiştirebilirsiniz; parametre ekleyemez veya kaldıramazsınız. Daha fazla bilgi için bkz. Delete.

Başvuru tarafından geçirilen parametreler nesnenin OutputParametersObjectDataSourceStatusEventArgs özelliğinde döndürülür.

Şunlara uygulanır

Ürün Sürümler
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1