以枚举作为下拉列表的数据源

今天看一个项目里用到了枚举作为下拉列表的数据源,感觉很不错,收藏下来,实现代码如下:

绑定枚举的名称:

DropDownList.DataSource= Enum.GetNames(typeof(枚举名称));
DropDownList.DataBind();

绑定枚举的值:

DropDownList.DataSource = Enum.GetValues(typeof(枚举名称));
DropDownList.DataBind();
原文地址:https://www.cnblogs.com/fumj/p/2555265.html