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();
查看全文
相关阅读:
mysql 更改字符集
修改pip源
git命令
virtualwrapper使用
Python环境搭建
IntellIJ IDEA 配置 Maven 以及 修改 默认 Repository
Spring4:JDBC
Spring3:AOP
Spring2:bean的使用
Spring1:Spring简介、环境搭建、源码下载及导入MyEclipse
原文地址:https://www.cnblogs.com/DotNet1010/p/1154065.html
最新文章
shui-prototype原型
shui-toString()
Vue-百度搜索下拉提示框
JS-JQ-垂直居中的侧边栏
shui-执行多个window.onload
JS-JQ-默认行为
JS-JQ-滚动条回到顶部
JS-JQ-事件冒泡
JS-JQ-拖拽
CSS-position:fixed兼容IE
热门文章
OS模块
解决CentOS“Zabbix discoverer processes 75% busy”的问题
yum运行时提示被锁住了解决办法
CentOS修改IP地址
zabbix被监控端代理设置
wget: command not found 解决方案
MYSQL常用命令(转)
Python之迭代器,生成器
mysql出现ERROR 1819 (HY000)的解决方法
安装zabbix需要php的两个模块php-bcmath和php-mbstring(转)
Copyright © 2011-2022 走看看