zoukankan
html css js c++ java
DropDownList 绑定 枚举 Enum
public
static
List
<
ListItem
>
GetEnumList(Type enumType,
bool
allAllOption)
{
if
(enumType.IsEnum
==
false
)
{
return
null
;
}
List
<
ListItem
>
list
=
new
List
<
ListItem
>
();
if
(allAllOption
==
true
)
{
list.Add(
new
ListItem(
"
--全部--
"
,
""
));
}
Type typeDescription
=
typeof
(DescriptionAttribute);
System.Reflection.FieldInfo[] fields
=
enumType.GetFields();
string
strText
=
string
.Empty;
string
strValue
=
string
.Empty;
foreach
(FieldInfo field
in
fields)
{
if
(field.IsSpecialName)
continue
;
strValue
=
field.GetRawConstantValue().ToString();
object
[] arr
=
field.GetCustomAttributes(typeDescription,
true
);
if
(arr.Length
>
0
)
{
strText
=
(arr[
0
]
as
DescriptionAttribute).Description;
}
else
{
strText
=
field.Name;
}
list.Add(
new
ListItem(strText, strValue));
}
return
list;
}
/**/
///
</summary>
///
派驻申请的状态
///
</summary>
public
enum
AccreditStatus
{
/**/
///
<summary>
///
已经结束
///
</summary>
[Description(
"
结束
"
)]
Pass
=
2
,
/**/
///
<summary>
///
新建
///
</summary>
[Description(
"
新建
"
)]
New
=
0
,
/**/
///
<summary>
///
在审批中
///
</summary>
[Description(
"
审批中
"
)]
Running
=
1
,
/**/
///
<summary>
///
被拒绝
///
</summary>
[Description(
"
被拒绝
"
)]
Refuse
=
-
1
}
this.ddlState.DataSource = Global.GetEnumList(typeof(AccreditStatus), true);
this.ddlState.DataTextField = "Text";
this.ddlState.DataValueField = "Value";
this.ddlState.DataBind();
查看全文
相关阅读:
WiFi流量劫持—— 浏览任意页面即可中毒!
POJ3614防晒霜 这个贪心有点东西(贪心+优先队列)
7月24日训练记录
环形均分纸牌问题(中位数)
7月23日训练总结
7.22学习总结
POJ 1176 Party Lamps&& USACO 2.2 派对灯(搜索)
尘埃落定,以梦为马,不负韶华
P1522 牛的旅行 Cow Tours(floyd)
分享一种解题的思想,有关时间复杂度探讨
原文地址:https://www.cnblogs.com/DotNet1010/p/1154065.html
最新文章
Red Hat安装虚拟带库
linux用户和组
linux下sendmail
linux源代码获取
linux单用户模式
VMware基本用法
【Java基本功】一文了解Java中继承、封装、多态的细节
【Java基本功】一文读懂final关键字的用法
【Java基本功】一文读懂String及其包装类的实现原理
「Java基本功」一文读懂Java内部类的用法和原理
热门文章
大牛给计算机方向学生的 7 个建议
Java基础总结大纲(一)
自我反省(总是自以为是)
防止代码变质的思考与方法
注重实效的架构师——大胆行前人未行之路
java动态跟踪分析工具BTrace实现原理
BTrace使用总结
btrace一些你不知道的事(源码入手)
调试工具BTrace 的使用--例子
程序猿也爱学英语(上),有图有真相
Copyright © 2011-2022 走看看