【发布时间】:2012-10-09 21:43:07
【问题描述】:
我的 aspx 中有以下下拉菜单:
<aspx:DropDownList
ID="ddl1"
runat="server"/>
在代码隐藏 (C#) 中,我想从 DropDownList 中检索值。
我这样填充了我的下拉列表:
ddl1.DataSource = LocationOfData;
ddl1.DataBind();
LocationOfData 返回 CustomType 类型。编辑:CustomType 是一个枚举。
我希望能够做到以下几点:
CustomType? myvar = ddl1.Text
换句话说,使用我的 CustomType 创建一个可为空的变量并将其设置为等于下拉列表中的变量。但是我只能从 ddl1 中检索文本(字符串)的类型。
【问题讨论】:
-
CustomType的定义是什么? ?
-
在进一步检查我的问题后,我意识到 CustomType 是一个值的枚举。
-
string 是引用类型,你只需要为值类型创建一个可为空的变量。
-
如果 CustomType 被定义为 public enum CustomType { etc.... } 那么应该可以创建一个可为空的类型 CustomType?