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

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

ObjectDataSourceView.InsertParameters プロパティ

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

InsertMethod メソッドによって使用されるパラメータ格納するパラメータ コレクション取得します

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

Public ReadOnly Property
 InsertParameters As ParameterCollection
Dim instance As ObjectDataSourceView
Dim value As ParameterCollection

value = instance.InsertParameters
public ParameterCollection InsertParameters { get;
 }
public:
property ParameterCollection^ InsertParameters {
    ParameterCollection^ get ();
}
/** @property */
public ParameterCollection get_InsertParameters ()
public function get InsertParameters
 () : ParameterCollection

プロパティ
InsertMethod プロパティによって使用されるパラメータ格納している ParameterCollection。

解説解説
使用例使用例

このセクションには、2 つコード例含まれています。ビジネス オブジェクトおよび DetailsView コントロールで、ObjectDataSource コントロール使用してデータ挿入しフィルタ処理済みデータ表示する方法最初コード例示します最初コード例使用した Insert メソッド実装例2 番目のコード例示します

ビジネス オブジェクトおよび DetailsView コントロールで、ObjectDataSource コントロール使用してデータ挿入する方法次のコード例示しますDetailsView は、新しNorthwindEmployee レコードと、自動的に生成された [挿入] ボタン最初に表示しますDetailsView コントロールフィールドデータ入力した後、[挿入] ボタンクリックします。InsertMethod プロパティは、Insert 操作実行するメソッド識別します。

[挿入] ボタンクリックすると、InsertMethod プロパティ指定されメソッド、および InsertParameters コレクション指定されパラメータ使用して Insert 操作実行されます。このコード例では、スーパバイザID対応する InsertParameters コレクション内のパラメータ1 つ指定されています。その理由は、この IDDetailsView コントロール用の Fields コレクション内に BoundField オブジェクトとして表示されていても、ObjectDataSource コントロールは文字列として渡されるためです。Int32 値に設定した Type プロパティ指定して、この ID明示的に InsertParameters コレクション追加すると、この IDstring ではなくint として、ObjectDataSource によってメソッド正しく渡されます。

Insert 操作実行すると、InsertMethod プロパティ識別されメソッド呼び出されます。オブジェクトInsert メソッドパラメータを含むメソッド シグネチャ持っている場合Insert正常に完了するためには、InsertParameters コレクションメソッド シグネチャ パラメータ一致する名前のパラメータがある必要があります

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB"
 Assembly="Samples.AspNet.VB"
 %>
<%@ Import namespace="Samples.AspNet.VB"
 %>
<%@ Page language="vb" %>
<html>
  <head>
    <title>ObjectDataSource - VB Example</title>
  </head>
  <body>
    <form id="Form1" method="post"
 runat="server">

        <asp:detailsview
          id="DetailsView1"
          runat="server"
          autogenerateinsertbutton="True"
          autogeneraterows="false"
          datasourceid="ObjectDataSource1" >
          <fields>
            <asp:BoundField headertext="FirstName"
 datafield="FirstName" />
            <asp:BoundField headertext="LastName"
   datafield="LastName" />
            <asp:BoundField headertext="Title"
      datafield="Title" />
            <asp:BoundField headertext="Courtesy"
   datafield="Courtesy" />
            <asp:BoundField headertext="Supervisor"
 datafield="Supervisor" />
          </fields>
        </asp:detailsview>

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetEmployee"
          insertmethod="InsertNewEmployeeWrapper"
          typename="Samples.AspNet.VB.EmployeeLogic"
 >
          <selectparameters>
            <asp:parameter name="anID" defaultvalue="-1"
 />
          </selectparameters>
          <insertparameters>
            <asp:parameter name="Supervisor" type="Int32"
 />
          </insertparameters>
        </asp:objectdatasource>

    </form>
  </body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS"
 Assembly="Samples.AspNet.CS" %>
<%@ Import namespace="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<html>
  <head>
    <title>ObjectDataSource - C# Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">

        <asp:detailsview
          id="DetailsView1"
          runat="server"
          autogenerateinsertbutton="True"
          autogeneraterows="false"
          datasourceid="ObjectDataSource1" >
          <fields>
            <asp:BoundField headertext="FirstName" datafield="FirstName"
 />
            <asp:BoundField headertext="LastName"   datafield="LastName"
 />
            <asp:BoundField headertext="Title"      datafield="Title"
 />
            <asp:BoundField headertext="Courtesy"   datafield="Courtesy"
 />
            <asp:BoundField headertext="Supervisor" datafield="Supervisor"
 />
          </fields>
        </asp:detailsview>

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetEmployee"
          insertmethod="InsertNewEmployeeWrapper"
          typename="Samples.AspNet.CS.EmployeeLogic" >
          <selectparameters>
            <asp:parameter name="anID" defaultvalue="-1" />
          </selectparameters>
          <insertparameters>
            <asp:parameter name="Supervisor" type="Int32"
 />
          </insertparameters>
        </asp:objectdatasource>

    </form>
  </body>
</html>

前のコード例使用した Insert メソッド実装例次のコード例示しますInsertNewEmployeeWrapper メソッドEmployeeLogic 中間層オブジェクト追加されているため、実際ビジネス ロジックをあまりリライトせずに、オブジェクトWeb シナリオObjectDataSource コントロール簡単に使用できるようになります

' This InsertNewEmployeeWrapper method is a wrapper method that enables
' the use of ObjectDataSource and InsertParameters, without
' substantially rewriting the true implementation for the NorthwindEmployee
' or the EmployeeLogic objects.
'
' The parameters to the method must be named the same as the
' DataControlFields used by the GridView or DetailsView controls.
Public Shared Sub InsertNewEmployeeWrapper(FirstName
 As String, LastName As
 String, Title As String, Courtesy As String, Supervisor As Integer)
   ' Build the NorthwindEmployee object and
   ' call the true  implementation.
   Dim tempEmployee As New
 NorthwindEmployee()

   tempEmployee.FirstName = FirstName
   tempEmployee.LastName = LastName
   tempEmployee.Title = Title
   tempEmployee.Courtesy = Courtesy
   tempEmployee.Supervisor = Supervisor

   ' Call the true implementation.
   InsertNewEmployee(tempEmployee)
End Sub 'InsertNewEmployeeWrapper


Public Shared Sub InsertNewEmployee(ne
 As NorthwindEmployee)
   Dim retval As Boolean
 = ne.Save()
   If Not retval Then
      Throw New NorthwindDataException("InsertNewEmployee
 failed.")
   End If
End Sub 'InsertNewEmployee
// This InsertNewEmployeeWrapper method is a wrapper method that enables
// the use of ObjectDataSource and InsertParameters, without
// substantially rewriting the true implementation for the NorthwindEmployee
// or the EmployeeLogic objects.
//
// The parameters to the method must be named the same as the
// DataControlFields used by the GridView or DetailsView controls.
public static void InsertNewEmployeeWrapper
 (string FirstName,
                                             string LastName,
                                             string Title,
                                             string Courtesy,
                                             int    Supervisor)
{
  // Build the NorthwindEmployee object and
  // call the true  implementation.
  NorthwindEmployee tempEmployee = new NorthwindEmployee();

  tempEmployee.FirstName  = FirstName;
  tempEmployee.LastName   = LastName;
  tempEmployee.Title      = Title;
  tempEmployee.Courtesy   = Courtesy;
  tempEmployee.Supervisor = Supervisor;

  // Call the true implementation.
  InsertNewEmployee(tempEmployee);
}

public static void InsertNewEmployee(NorthwindEmployee
 ne) {
  bool retval = ne.Save();
  if (! retval) { throw new NorthwindDataException("InsertNewEmployee
 failed."); }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ObjectDataSourceView クラス
ObjectDataSourceView メンバ
System.Web.UI.WebControls 名前空間
ObjectDataSourceView.InsertMethod プロパティ
Insert



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

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

   

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



ObjectDataSourceView.InsertParameters プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS