ObjectDataSourceView.UpdateMethod プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ObjectDataSourceView.UpdateMethod プロパティの意味・解説 

ObjectDataSourceView.UpdateMethod プロパティ

メモ : このプロパティは、.NET Framework version 2.0 で新しく追加されたものです。

データを更新するために ObjectDataSourceView オブジェクトが呼び出すメソッドまたは関数の名前を取得または設定します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Dim instance As ObjectDataSourceView
Dim value As String

value = instance.UpdateMethod

instance.UpdateMethod = value
public string UpdateMethod { get;
 set; }
public:
property String^ UpdateMethod {
    String^ get ();
    void set (String^ value);
}
/** @property */
public String get_UpdateMethod ()

/** @property */
public void set_UpdateMethod (String value)
public function get UpdateMethod
 () : String

public function set UpdateMethod
 (value : String)

プロパティ値
データを更新するために ObjectDataSourceView が使用するメソッドまたは関数の名前を表す文字列。既定値は空の文字列 ("") です。

解説解説

ObjectDataSourceView オブジェクトは、UpdateMethod プロパティで指定されたメソッドが更新をバッチ処理するのではなく 1 回に 1 つずつ実行することを前提にしています。

このメソッドには、インスタンス メソッドまたは static (Visual Basic の場合は Shared) なメソッドを指定できます。インスタンス メソッドの場合は、UpdateMethod プロパティで指定するメソッドが呼び出されるたびにビジネス オブジェクトが作成され、破棄されます。ObjectCreated イベントを処理することで、UpdateMethod プロパティで指定したメソッドを呼び出す前にビジネス オブジェクトに対して作業を実行できます。UpdateMethod メソッドが呼び出された後に発生する ObjectDisposing イベントを処理することもできます (Dispose は、ビジネス オブジェクトが IDisposable インターフェイスを実装する場合にだけ呼び出されます)。メソッドが static (Visual Basic では Shared) なメソッドである場合は、ビジネス オブジェクトが作成されないので、これらのイベントを処理できません。

ObjectDataSource オブジェクトを扱うビジネス オブジェクトが複数のメソッドまたは関数を同じ名前で実装すると (メソッドのオーバーロード)、データ ソース コントロールは、UpdateParameters コレクションのパラメータなどの一連の条件に従って適切なものを呼び出そうとします。UpdateParameters コレクション内のパラメータが、UpdateMethod プロパティで指定されたメソッド シグネチャのパラメータと一致しない場合、データ ソースは例外をスローします。

詳細については、ObjectDataSource.UpdateMethod のトピックを参照してください。

UpdateMethod プロパティの値はビューステートに格納されます。

使用例使用例

DropDownList コントロール、TextBox コントロール、および複数の ObjectDataSource コントロールを使用してデータを更新する方法を次のコード例に示します。TextBox コントロールがアドレス情報の入力と更新に使用されるのに対し、DropDownList は、NorthwindEmployee の名前を表示します。UpdateParameters コレクションには、DropDownList で選択された値に関連付けられた ControlParameter オブジェクトが格納されているため、Update 操作を発生させるボタンは、従業員を選択するまで有効になりません。

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB"
 Assembly="Samples.AspNet.VB"
 %>
<%@ Page language="vb" %>
<%@ Import namespace="Samples.AspNet.VB"
 %>

<Script runat="server">

' Add parameters and initialize the user interface
' only if an employee is selected.
Private Sub Page_Load(sender As
 Object, e As EventArgs)

  ' Be sure the text boxes are initialized with
  ' data from the currently selected employee.
  Dim selectedEmployee As NorthwindEmployee
  selectedEmployee = EmployeeLogic.GetEmployee(DropDownList1.SelectedValue)

  If Not selectedEmployee Is
 Nothing Then
    AddressBox.Text    = selectedEmployee.Address
    CityBox.Text       = selectedEmployee.City
    PostalCodeBox.Text = selectedEmployee.PostalCode

    Button1.Enabled = True
  Else
    Button1.Enabled = False
  End If
End Sub ' Page_Load

' Press the button to update.
Private Sub Btn_UpdateEmployee (sender As
 Object, e As CommandEventArgs )
  ObjectDataSource2.Update()
End Sub ' Btn_UpdateEmployee

</Script>
<html>
  <head>
    <title>ObjectDataSource - VB 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.VB.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. -->

        <!-- Security Note: The ObjectDataSource uses a FormParameter,
             Security Note: which does not perform validation
 of input from the client.
             Security Note: To validate the value of
 the FormParameter,
             Security Note: handle the Updating event. -->

        <asp:objectdatasource
          id="ObjectDataSource2"
          runat="server"
          updatemethod="UpdateEmployeeWrapper"
          typename="Samples.AspNet.VB.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>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS"
 Assembly="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<%@ Import namespace="Samples.AspNet.CS" %>
<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();
}
</Script>
<html>
  <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. -->

        <!-- Security Note: The ObjectDataSource uses a FormParameter,
             Security Note: which does not perform validation of input from the client.
             Security Note: To validate the value of the FormParameter,
             Security Note: handle the Updating event. -->

        <asp:objectdatasource
          id="ObjectDataSource2"
          runat="server"
          updatemethod="UpdateEmployeeWrapper"
          typename="Samples.AspNet.CS.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>
<%@ 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>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ObjectDataSourceView クラス
ObjectDataSourceView メンバ
System.Web.UI.WebControls 名前空間
UpdateParameters
Update
Update



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「ObjectDataSourceView.UpdateMethod プロパティ」の関連用語

ObjectDataSourceView.UpdateMethod プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ObjectDataSourceView.UpdateMethod プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS