使用 Enum 來當資料來源,可使用在 dropdownlist, ComboList
國外的
http://www.codeproject.com/KB/cs/enumdatabinding.aspx?select=2217063
黑暗大的
http://blog.darkthread.net/post-2011-04-15-enum-desc-to-list.aspx
使用時,要 Imports System.ComponentModel
VB.NET 寫法
Public Enum EnumAAA
<Description("Today AAA")> AAA
<Description("Today BBB")> BBB
End Enum
Public Shared Function EnumDescription(ByVal EnumConstant As [Enum]) As String
Dim fi As Reflection.FieldInfo = EnumConstant.GetType().GetField(EnumConstant.ToString())
Dim aattr() As DescriptionAttribute = DirectCast(fi.GetCustomAttributes(GetType(DescriptionAttribute), False), DescriptionAttribute())
If aattr.Length > 0 Then
Return aattr(0).Description
Else
Return EnumConstant.ToString()
End If
End Function