ObjectDataSource.DataObjectTypeName プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
ObjectDataSource コントロールが、データ バインド コントロールから個々の値を渡す代わりに、データの更新、挿入、削除の各操作のパラメーターに使用するクラスの名前を取得または設定します。
public:
property System::String ^ DataObjectTypeName { System::String ^ get(); void set(System::String ^ value); };
public string DataObjectTypeName { get; set; }
member this.DataObjectTypeName : string with get, set
Public Property DataObjectTypeName As String
プロパティ値
ObjectDataSource が Insert()、Update()、Delete() の各操作のパラメーターとして使用できるオブジェクトの型を識別する、部分修飾クラス名または完全修飾クラス名。 既定値は、空の文字列 ("") です。
例
このセクションには、2 つのコード例が含まれています。 最初のコード例では、プロパティを使用して、すべてのパラメーター値を 1 つのオブジェクトに結合する型を実装する方法を DataObjectTypeName 示します。 2 番目のコード例は、最初のコード例で使用される 2 つのクラスを使用する Web ページを示しています。
次のコード例では、プロパティを使用して、すべてのパラメーター値を 1 つのオブジェクトに結合する型を実装する方法を DataObjectTypeName 示します。 クラスの AggregateData
select メソッドは、2 つの列を持つオブジェクトを返DataTableします。Name
Number
同様に、このクラスは NewData
2 つの読み取り/書き込みプロパティと Number
. Name
クラスのメソッドは Insert
、 AggregateData
型 NewData
の 1 つのパラメーターを受け取ります。 の TypeName
プロパティ ObjectDataSource は次に AggregateData
設定され、 DataObjectTypeName プロパティは NewData
.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Samples.AspNet.CS
{
/// <summary>
/// Summary description for AggregateData
/// </summary>
public class AggregateData
{
public AggregateData()
{
}
static DataTable table;
private DataTable CreateData()
{
table = new DataTable();
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Number", typeof(int));
table.Rows.Add(new object[] { "one", 1 });
table.Rows.Add(new object[] { "two", 2 });
table.Rows.Add(new object[] { "three", 3 });
return table;
}
public DataTable Select()
{
if (table == null)
{
return CreateData();
}
else
{
return table;
}
}
public int Insert(NewData newRecord)
{
table.Rows.Add(new object[] { newRecord.Name, newRecord.Number });
return 1;
}
}
public class NewData
{
private string nameValue;
private int numberValue;
public string Name
{
get { return nameValue; }
set { nameValue = value; }
}
public int Number
{
get { return numberValue; }
set { numberValue = value; }
}
}
}
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Namespace Samples.AspNet.VB
Public Class AggregateData
Public Sub New()
End Sub
Shared table As DataTable
Private Function CreateData() As DataTable
table = New DataTable()
table.Columns.Add("Name", GetType(String))
table.Columns.Add("Number", GetType(Integer))
table.Rows.Add(New Object() {"one", 1})
table.Rows.Add(New Object() {"two", 2})
table.Rows.Add(New Object() {"three", 3})
Return table
End Function
Public Function SelectMethod() As DataTable
If table Is Nothing Then
Return CreateData()
Else
Return table
End If
End Function
Public Function Insert(ByVal newRecord As NewData) As Integer
table.Rows.Add(New Object() {newRecord.Name, newRecord.Number})
Return 1
End Function
End Class
Public Class NewData
Private nameValue As String
Private numberValue As Integer
Public Property Name() As String
Get
Return nameValue
End Get
Set(ByVal value As String)
nameValue = value
End Set
End Property
Public Property Number() As Integer
Get
Return numberValue
End Get
Set(ByVal value As Integer)
numberValue = value
End Set
End Property
End Class
End Namespace
次のコード例は、前のコード例で使用した 2 つのクラスを使用する Web ページを示しています。
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %>
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ObjectDataSource - DataObjectTypeName Property Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DetailsView
ID="DetailsView1"
runat="server"
AllowPaging="True"
AutoGenerateInsertButton="True"
DataSourceID="ObjectDataSource1"
Height="50px"
Width="125px">
</asp:DetailsView>
<asp:ObjectDataSource
ID="ObjectDataSource1"
runat="server"
DataObjectTypeName="Samples.AspNet.CS.NewData"
InsertMethod="Insert"
SelectMethod="Select"
TypeName="Samples.AspNet.CS.AggregateData">
</asp:ObjectDataSource>
</div>
</form>
</body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB" Assembly="Samples.AspNet.VB" %>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ObjectDataSource - DataObjectTypeName Property Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DetailsView
ID="DetailsView1"
runat="server"
AllowPaging="True"
AutoGenerateInsertButton="True"
DataSourceID="ObjectDataSource1"
Height="50px"
Width="125px">
</asp:DetailsView>
<asp:ObjectDataSource
ID="ObjectDataSource1"
runat="server"
DataObjectTypeName="Samples.AspNet.VB.NewData"
InsertMethod="Insert"
SelectMethod="SelectMethod"
TypeName="Samples.AspNet.VB.AggregateData">
</asp:ObjectDataSource>
</div>
</form>
</body>
</html>
注釈
メソッドにDelete渡されるUpdateInsert複数のパラメーターを指定する代わりに、複数のデータ フィールド値を集計する 1 つのオブジェクトを作成できます。 この 1 つのオブジェクトは、複数のパラメーターではなく、メソッドに渡されます。
データ バインド コントロールに ObjectDataSource バインドされるコントロールの既定の動作は、データ バインド コントロールがデータ ソース内の各パラメーターのオブジェクトを作成 Parameter することです。 ビジネス オブジェクトに多くのフィールドがある場合、結果のメソッドには多くのフィールドもあります。 この DataObjectTypeName プロパティを使用すると、各データ フィールドのプロパティを持つ型を指定できます。 次に、複数のパラメーターをメソッドに渡す代わりに、ランタイムは 1 つのオブジェクトを作成し、そのすべてのプロパティを設定します。 この 1 つのオブジェクトは、メソッド呼び出しのパラメーター コレクションに追加されます。
プロパティで DataObjectTypeName 指定される型には、パラメーターを持たないパラメーターなしのコンストラクターが必要です。そのため ObjectDataSource 、コントロールは型のインスタンスを作成できます。 この型には、コントロールがデータ バインド コントロールから渡される値をオブジェクトに設定できるようにする ObjectDataSource 設定可能なプロパティも必要です。 コントロールの ObjectDataSource プロパティ名は、データ バインド コントロールによって渡される値のパラメーター名と正確に一致することが期待されます。
プロパティがDataObjectTypeName設定され、ObjectDataSourceコントロールがデータ バインド コントロールに関連付けられている場合、プロパティとDeleteMethodプロパティによってInsertMethod指定されるメソッドには、プロパティでDataObjectTypeName指定された型のパラメーターが 1 つ必要です。 プロパティが ConflictDetection 値に OverwriteChanges 設定されている場合、プロパティで UpdateMethod 指定されるメソッドには、プロパティで DataObjectTypeName 指定された型のパラメーターが 1 つ必要です。 プロパティがConflictDetection値にCompareAllValues設定されている場合、プロパティで指定されるメソッドには、プロパティでUpdateMethodDataObjectTypeName指定された型の 2 つのパラメーターが必要です。 最初のパラメーターには元の値が含まれています。2 番目のパラメーターには新しい値が含まれています。
プロパティはDataObjectTypeName、コントロールにDataObjectTypeName関連付ObjectDataSourceけられているプロパティにObjectDataSourceViewデリゲートします。