DataObjectAttribute 類別

定義

將型別識別為適合繫結至 ObjectDataSource 物件的物件。 此類別無法獲得繼承。

public ref class DataObjectAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class)]
public sealed class DataObjectAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class)>]
type DataObjectAttribute = class
    inherit Attribute
Public NotInheritable Class DataObjectAttribute
Inherits Attribute
繼承
DataObjectAttribute
屬性

範例

下列程式碼範例示範如何套用 DataObjectAttribute 屬性來指出物件適合系結至 ObjectDataSource 物件。 在此範例中 NorthwindData ,物件適用于與 物件搭配 ObjectDataSource 使用。

[DataObjectAttribute]
public class NorthwindData
{  
  public NorthwindData() {}

  [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
  public static IEnumerable GetAllEmployees()
  {
    AccessDataSource ads = new AccessDataSource();
    ads.DataSourceMode = SqlDataSourceMode.DataReader;
    ads.DataFile = "~//App_Data//Northwind.mdb";
    ads.SelectCommand = "SELECT EmployeeID,FirstName,LastName FROM Employees";
    return ads.Select(DataSourceSelectArguments.Empty);
  }

  // Delete the Employee by ID.
  [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
  public void DeleteEmployeeByID(int employeeID)
  {
    throw new Exception("The value passed to the delete method is "
                         + employeeID.ToString());
  }
}
<DataObjectAttribute()> _
Public Class NorthwindData

  <DataObjectMethodAttribute(DataObjectMethodType.Select, True)> _
  Public Shared Function GetAllEmployees() As IEnumerable
    Dim ads As New AccessDataSource()
    ads.DataSourceMode = SqlDataSourceMode.DataReader
    ads.DataFile = "~/App_Data/Northwind.mdb"
    ads.SelectCommand = "SELECT EmployeeID,FirstName,LastName FROM Employees"
    Return ads.Select(DataSourceSelectArguments.Empty)
  End Function 'GetAllEmployees

  ' Delete the Employee by ID.
  <DataObjectMethodAttribute(DataObjectMethodType.Delete, True)> _
  Public Sub DeleteEmployeeByID(ByVal employeeID As Integer)
    Throw New Exception("The value passed to the delete method is " + employeeID.ToString())
  End Sub

End Class

備註

DataObjectAttribute使用 屬性來識別物件,以適合物件 ObjectDataSource 使用。 類別之類的 ObjectDataSourceDesigner 設計階段類別會 DataObjectAttribute 使用 屬性來呈現適合的物件,以系結至 ObjectDataSource 物件。

如需使用屬性的詳細資訊,請參閱 屬性

建構函式

DataObjectAttribute()

初始化 DataObjectAttribute 類別的新執行個體。

DataObjectAttribute(Boolean)

初始化 DataObjectAttribute 類別的新執行個體,並指出物件是否適合繫結至 ObjectDataSource 物件。

欄位

DataObject

表示類別在設計階段適合繫結至 ObjectDataSource 物件。 此欄位為唯讀。

Default

表示 DataObjectAttribute 類別的預設值,表示類別在設計階段適合繫結至 ObjectDataSource 物件。 此欄位為唯讀。

NonDataObject

表示類別在設計階段不適合繫結至 ObjectDataSource 物件。 此欄位為唯讀。

屬性

IsDataObject

取得值,指出物件在設計階段是否應被視為適合繫結至 ObjectDataSource 物件。

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)

方法

Equals(Object)

判斷這個 DataObjectAttribute 的執行個體是否符合另一個物件的模式。

GetHashCode()

傳回這個執行個體的雜湊碼。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

取得值,指出目前屬性值是否為屬性的預設值。

Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於