DataType 枚举


表示与数据字段和参数关联的数据类型的枚举。Represents an enumeration of the data types associated with data fields and parameters.

public enum class DataType
public enum DataType
type DataType = 
Public Enum DataType


CreditCard 14

表示信用卡号码。Represents a credit card number.

Currency 6

表示货币值。Represents a currency value.

Custom 0

表示自定义的数据类型。Represents a custom data type.

Date 2

表示日期值。Represents a date value.

DateTime 1

表示某个具体时间,以日期和当天的时间表示。Represents an instant in time, expressed as a date and time of day.

Duration 4

表示对象存在的一段连续时间。Represents a continuous time during which an object exists.

EmailAddress 10

表示电子邮件地址。Represents an email address.

Html 8

表示一个 HTML 文件。Represents an HTML file.

ImageUrl 13

表示图像的 URL。Represents a URL to an image.

MultilineText 9

表示多行文本。Represents multi-line text.

Password 11

表示密码值。Represent a password value.

PhoneNumber 5

表示电话号码值。Represents a phone number value.

PostalCode 15

表示邮政代码。Represents a postal code.

Text 7

表示所显示的文本。Represents text that is displayed.

Time 3

表示时间值。Represents a time value.

Upload 16

表示文件上载数据类型。Represents file upload data type.

Url 12

表示 URL 值。Represents a URL value.


下面的示例使用 DataTypeAttribute 属性来自定义 AdventureWorksLT 数据库中 customer 表的 EmailAddress 数据字段的显示。The following example uses the DataTypeAttribute attribute to customize the display of EmailAddress data field of the customer table in the AdventureWorksLT database. 电子邮件地址显示为超链接,而不是 ASP.NET 动态数据从内部数据类型推断出的简单文本。The email 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.

  • DataTypeAttribute通过 EmailAddress 在关联的元数据类中指定枚举值,将特性应用于 EmailAddress 数据字段。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 email address display is customized.

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

public partial class Customer

public class CustomerMetaData

    // Add type information.
    public object EmailAddress;

Imports System.Web.DynamicData
Imports System.ComponentModel.DataAnnotations

<MetadataType(GetType(CustomerMetadata))> _
Partial Public Class Customer

End Class

Public Class CustomerMetadata

    ' Add type information.
    <DataType(DataType.EmailAddress)> _
    Public EmailAddress As Object

End Class

若要编译代码示例,需要以下组件:To compile the example code, you need the following:

  • Visual Studio 2008 Service Pack 1 或 Visual Developer 2008 速成版 Service Pack 1。Visual Studio 2008 Service Pack 1 or Visual Developer 2008 Express Edition Service Pack 1.

  • AdventureWorksLT 示例数据库。The AdventureWorksLT sample database. 有关如何下载和安装 SQL Server 示例数据库的信息,请参阅 Microsoft SQL Server 产品示例:数据库For information about how to download and install the SQL Server sample database, see Microsoft SQL Server Product Samples: Database. 请确保为运行 (SQL Server 2005 或 SQL Server 2008) 的 SQL Server 版本安装正确的示例数据库版本。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.

有关字段模板用于自定义 EmailAddress 数据字段的显示的完整代码示例,请参见 DataTypeAttribute 属性。For the complete code example that the field template uses to customize the display of the EmailAddress data fields, see the DataTypeAttribute attribute.


此枚举用于指定要与数据列或参数关联的数据类型。This enumeration is used to specify the type of data to associate with a data column or a parameter. 使用 DataTypeAttribute 特性类来指定要与数据字段或参数关联的数据类型。You use the DataTypeAttribute attribute class to specify the data type you want to associate with the data field or parameter. 选择此枚举中的数据类型。You select the data type from this enumeration.

DataTypeAttribute特性允许使用比数据库内部类型更具体的类型来标记字段。The DataTypeAttribute attribute lets you mark fields by using a type that is more specific than the database intrinsic types. 例如,包含电子邮件地址的字符串数据字段可使用枚举值进行属性化 EmailAddressFor example, a string data field that contains email addresses can be attributed with the EmailAddress enumerated value. 此信息可由字段模板访问,并可修改数据字段的处理方式。This information can be accessed by the field templates and modify how the data field is processed.