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();
查看全文
相关阅读:
str_split 分隔中文出现乱码 替代函数
PHP 浮点数 转化 整数方法对比 ceil,floor,round,intval,number_format
php 判断字符串之间包含关系
不解之谜
正则匹配 特殊的 符号
PHP 判断字符串 是否 包含另一个字符串
PHP 删除 数组 指定成员
HTML 权重标签的使用
【PAT甲级】1094 The Largest Generation (25 分)(DFS)
【PAT甲级】1093 Count PAT's (25 分)
原文地址:https://www.cnblogs.com/tongdengquan/p/6090533.html
最新文章
tomcat部署https+TLS 1.2+Apple ATS支持
uboot补丁的分析
uboot补丁的使用
U-Boot移植
openWrt 安装与实践 II
openWrt 安装与实践
HTML5 lufylegend引擎学习(一) -- 剪刀石头布小游戏
HTML DIV充满整个屏幕
HTML innerHTML、textContext、innerText
HTML 元素居中的方法
热门文章
Ubuntu Samba
RequireJS 插件
MySQL 数据库的设计规范
Redis 3.0中文版学习(二)
PHP 快速排序
Redis 3.0中文版学习(一)
myeclipse 创建web project
tomcat安装问题
java 链接mysql
php array_flip() 删除数组重复元素
Copyright © 2011-2022 走看看