【发布时间】:2009-05-09 00:38:04
【问题描述】:
我有一个带有下拉 (asp:DropDownList) 控件的 ASP.NET 页面。我也有一个定义的 ENUM
Public Enum myEnumType As Integer
A
B
C
End Enum
我想用 ENUM 值之一定义每个 asp:ListItem 的“值”属性(当然,A、B、C 表示为字符串)。我还想将每个的“文本”值分配为一些不相关的字符串(例如“狗”、“猫”、“蚂蚁”)。
我想使用这个语法:
<asp:DropDownList ID="myCombo" runat="server">
<asp:ListItem Text="cat" Value="<%= myEnumType.A.toString() %>" />
<asp:ListItem Text="dog" Value="<%= myEnumType.B.toString() %>" />
<asp:ListItem Text="ant" Value="<%= myEnumType.C.toString() %>" />
</asp:DropDownList>
但在此类控件中使用
我怎样才能在声明性 ASP.NET 中做到这一点(而不是使用代码来创建每个项目)
【问题讨论】:
-
我使用枚举,因此当值更改时,我可以对解析的枚举使用“select case”语句。如果值是字符串,我需要在代码中有一个匹配的字符串。我不喜欢这个值不是强类型
标签: asp.net