Export (0) Print
Expand All

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
/** @attribute AttributeUsageAttribute(AttributeTargets.Class) */ 
public final class DataObjectAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Class) 
public final class DataObjectAttribute extends Attribute
Not applicable.

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 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft