Export (0) Print
Expand All

DataType Enumeration

Represents an enumeration of the data types associated with data fields and parameters.

Namespace:  System.ComponentModel.DataAnnotations
Assembly:  System.ComponentModel.DataAnnotations (in System.ComponentModel.DataAnnotations.dll)

public enum DataType

Member nameDescription
CreditCardRepresents a credit card number.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsCurrencyRepresents a currency value.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsCustomRepresents a custom data type.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsDateRepresents a date value.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsDateTimeRepresents an instant in time, expressed as a date and time of day.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsDurationRepresents a continuous time during which an object exists.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsEmailAddressRepresents an e-mail address.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsHtmlRepresents an HTML file.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsImageUrlRepresents a URL to an image.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsMultilineTextRepresents multi-line text.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsPasswordRepresent a password value.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsPhoneNumberRepresents a phone number value.
PostalCodeRepresents a postal code.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsTextRepresents text that is displayed.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsTimeRepresents a time value.
UploadRepresents file upload data type.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsUrlRepresents a URL value.

This enumeration is used to specify the type of data to associate with a data column or a parameter. You use the DataTypeAttribute class to specify the data type you want to associate with the data field or parameter. You select the data type from this enumeration.

The DataTypeAttribute attribute lets you mark fields by using a type that is more specific than the database intrinsic types. For example, a string data field that contains e-mail addresses can be attributed with the EmailAddress type. This information can be accessed by the field templates and modify how the data field is processed.

The following table lists the data types Dynamic Data provides.

The following example uses the DataTypeAttribute to customize the display of EmailAddress data field of the customer table in the AdventureWorksLT database. The e-mail addresses are shown as hyperlinks instead of the simple text that ASP.NET Dynamic Data would have inferred from the intrinsic data type.

The example code:

  • Implements a metadata partial class for the related table and the associated metadata class.

  • Applies the DataTypeAttribute attribute to the EmailAddress data field by specifying the EmailAddress enumerated value in the associated metadata class. This indicates to the Text.ascx field template that the e-mail address display is customized.

using System;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations;


[MetadataType(typeof(CustomerMetaData))]
public partial class Customer
{


}

public class CustomerMetaData
{

    // Add type information.
    [DataType(DataType.EmailAddress)]
    public object EmailAddress;

}

To compile the example code, you need the following:

  • Visual Studio 2008 Service Pack 1 or Visual Developer 2008 Express Edition Service Pack 1.

  • The AdventureWorksLT sample database. For information about how to download and install the SQL Server sample database, see Microsoft SQL Server Product Samples: Database on the CodePlex site. Make sure that you install the correct version of the sample database for the version of SQL Server that you are running (SQL Server 2005 or SQL Server 2008).

  • A Dynamic Data Web site. This enables you to create a data context for the database and the class that contains the data field to customize and the methods to override. In addition, it creates the environment in which to use the page described before. For more information, see Walkthrough: Creating a New Dynamic Data Web Site Using Scaffolding.

For the complete code example that the field template uses to customize the display of the EmailAddress data fields, see DataTypeAttribute.

.NET Framework

Supported in: 4.5, 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft