本文整理匯總了VB.NET中System.ComponentModel.DataAnnotations.DataTypeAttribute類的典型用法代碼示例。如果您正苦於以下問題:VB.NET DataTypeAttribute類的具體用法?VB.NET DataTypeAttribute怎麽用?VB.NET DataTypeAttribute使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了DataTypeAttribute類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1:
' 導入命名空間
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
示例2: OnDataBinding
' 導入命名空間
Imports System.Linq
Imports System.Web.UI.WebControls
Imports System.Web.DynamicData
Imports System.ComponentModel.DataAnnotations
Partial Public Class TextField
Inherits System.Web.DynamicData.FieldTemplateUserControl
Protected Overloads Overrides Sub OnDataBinding(ByVal e As EventArgs)
MyBase.OnDataBinding(e)
Dim processed As Boolean = False
Dim metadata As DataTypeAttribute = _
MetadataAttributes.OfType(Of DataTypeAttribute)().FirstOrDefault()
If metadata IsNot Nothing Then
If metadata.DataType = DataType.EmailAddress Then
If Not String.IsNullOrEmpty(FieldValueString) Then
processed = True
Dim hyperlink As New HyperLink()
hyperlink.Text = FieldValueString
hyperlink.NavigateUrl = "mailto:" + FieldValueString
Controls.Add(hyperlink)
End If
End If
End If
If Not processed Then
Dim literal As New Literal()
literal.Text = FieldValueString
Controls.Add(literal)
End If
End Sub
End Class