DataType DataType DataType DataType Enum

定义

表示与数据字段和参数关联的数据类型的枚举。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 CreditCard CreditCard CreditCard 14

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

Currency Currency Currency Currency 6

表示货币值。Represents a currency value.

Custom Custom Custom Custom 0

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

Date Date Date Date 2

表示日期值。Represents a date value.

DateTime DateTime DateTime DateTime 1

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

Duration Duration Duration Duration 4

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

EmailAddress EmailAddress EmailAddress EmailAddress 10

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

Html Html Html Html 8

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

ImageUrl ImageUrl ImageUrl ImageUrl 13

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

MultilineText MultilineText MultilineText MultilineText 9

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

Password Password Password Password 11

表示密码值。Represent a password value.

PhoneNumber PhoneNumber PhoneNumber PhoneNumber 5

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

PostalCode PostalCode PostalCode PostalCode 15

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

Text Text Text Text 7

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

Time Time Time Time 3

表示时间值。Represents a time value.

Upload Upload Upload Upload 16

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

Url Url Url 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.

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


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

 
}

public class CustomerMetaData
{

    // Add type information.
    [DataType(DataType.EmailAddress)]
    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 版本 (SQL Server 2005 或 SQL Server 2008) 安装示例数据库的正确版本。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. 例如, 包含电子邮件地址的字符串数据字段可使用EmailAddress枚举值进行属性化。For 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.

适用于

另请参阅