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 的物件。

欲了解更多屬性的使用資訊,請參閱屬性。

建構函式

名稱 Description
DataObjectAttribute()

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

DataObjectAttribute(Boolean)

初始化該類別的新實例 DataObjectAttribute ,並指示物件是否適合綁定到物件 ObjectDataSource

欄位

名稱 Description
DataObject

表示該類別適合在設計時綁定到物件 ObjectDataSource 。 此欄位僅供讀取。

Default

代表類別的 DataObjectAttribute 預設值,表示該類別適合在設計時綁定物件 ObjectDataSource 。 此欄位僅供讀取。

NonDataObject

表示該類別在設計時不適合綁定物件 ObjectDataSource 。 此欄位僅供讀取。

屬性

名稱 Description
IsDataObject

取得一個值,指示物件在設計時是否適合綁定物件 ObjectDataSource

TypeId

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

(繼承來源 Attribute)

方法

名稱 Description
Equals(Object)

判斷該實例 DataObjectAttribute 是否符合另一個物體的模式。

GetHashCode()

傳回這個實例的哈希碼。

GetType()

取得目前實例的 Type

(繼承來源 Object)
IsDefaultAttribute()

會取得一個值,表示該屬性目前值是否為預設值。

Match(Object)

在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

明確介面實作

名稱 Description
_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)

適用於