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();
查看全文
相关阅读:
淘宝质量属性场景分析
关于软件架构师如何工作(阅读架构漫谈感悟)
06有效需求设计阅读笔记之六
05有效需求设计阅读笔记之五
xxx征集系统项目目标文档
04有效需求设计阅读笔记之四
03有效需求设计阅读笔记之三
02有效需求设计阅读笔记之二
01有效需求设计阅读笔记之一
问题账户需求分析
原文地址:https://www.cnblogs.com/DotNet1010/p/1154065.html
最新文章
选择:包旅游车去
电梯演说模板练习
图书管理系统的设计说明
阅览敏捷开发的感想
关于软件开发团队的模式的个人意见
Android demo
Friend's Code Review
程序员的神经
My Code Review
在Eclipse中实现数组中最大子数组之和
热门文章
第二阶段冲刺 NO.1
第一次绩效评估
针对各组项目的改进意见
冲刺博客 十
16组小组博客检查
冲刺博客 九
冲刺博客 八
冲刺博客 七
冲刺博客 六
冲刺博客 五
Copyright © 2011-2022 走看看