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();
查看全文
相关阅读:
WCF客户端链接服务超时客户端close
C# byte数组常用扩展浅析(转)
代码生成相关工具及技术
已处理证书链,但是在不受信任提供程序信任的根证书中终止。
清理SQL Server数据库日志的两种方法
开源框架项目列表
SQL Server数据库文件恢复技术
VS2008找不到导出模板
jquery 学习笔记(二)
方法的参数的默认值设置
原文地址:https://www.cnblogs.com/tongdengquan/p/6090533.html
最新文章
Servlet中取得application对象的两种方法
在一段英文字母中找出,每个字母的重复数量的方法
数组翻转的方法(java实现)
ORACLE/SQL用函数进行每年,每月,每周,每日的数据汇总
oracle中的exists 和not exists 用法详解
插入排序,选择排序,冒泡排序等常用排序算法(java实现)
Hash 函数的常用算法和应用领域 Angels
Hypertable hbase hdfs kfs java与c++的较量 Angels
写得挺有深度 转载一下 hadoop high avilable 相关 Angels
hadoop上传数据问题 Angels
热门文章
Linux 内存泄露调试工具 Angels
Hadoop namenode启动瓶颈分析 Angels
我对中间件的理解 Angels
c++定义的强制转换 Angels
Linux 下面的硬盘分区 (比较好的资料 收藏) Angels
正则表达式 很强大 Angels
开博了!
机器学习相关知识整理系列之一:决策树算法原理及剪枝(ID3,C4.5,CART)
压缩数据库
ASP.net中的几个概念
Copyright © 2011-2022 走看看