Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

DataObjectAttribute Class

Identifies a type as an object suitable for binding to an ObjectDataSource object. This class cannot be inherited.

Namespace:  System.ComponentModel
Assembly:  System (in System.dll)
[AttributeUsageAttribute(AttributeTargets.Class)]
public sealed class DataObjectAttribute : Attribute

Use the DataObjectAttribute attribute to identify an object as suitable for use by an ObjectDataSource object. Design-time classes such as the ObjectDataSourceDesigner class use the DataObjectAttribute attribute to present suitable objects to bind to an ObjectDataSource object.

For more information about using attributes, see Extending Metadata Using Attributes.

The following code example demonstrates how you can apply the DataObjectAttribute attribute to indicate an object is suitable for binding to an ObjectDataSource object. In this example, the NorthwindData object is intended for use with an ObjectDataSource object.

[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());
  }
}
System.Object
  System.Attribute
    System.ComponentModel.DataObjectAttribute
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

.NET Compact Framework

Supported in: 3.5, 2.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.