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();
查看全文
相关阅读:
Djiango项目的创建以及配置介绍1
最大矩形土地 单调栈或者DP
0917 lxs 反思
0915 反思
codeforces 1209/C Paint the Digits 观察
NOIP2014 解方程 秦九韶算法+多项式处理
整数拆分问题
机器人M号
有趣的数列 唯一分解定理+卡特兰数
数位DP 不要62
原文地址:https://www.cnblogs.com/tongdengquan/p/6090533.html
最新文章
Python+Selenium自动化测试教程连载(1)
TCP粘包问题
socket
网络编程
异常处理
面向对象高级
面向对象之多态
面向对象之封装
面向对象之继承
面向对象编程
热门文章
xml模块、项目开发过程
Djiango ajax请求数据/分页器
Djiango orm 补充
Djiango orm 单表查询
Djiango orm 多表查询
Djiango orm 单表查询
Djiango模板导入
Djiango模板语言DTL
Djiango路由分发/伪静态页面/request对象/FBV CBV/文件上传
Djiango各组成部分及功能介绍
Copyright © 2011-2022 走看看