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();
查看全文
相关阅读:
ExtJS学习之路第一步:对比jQuery,认识ExtJS
创建Windows服务(C++)
吴恩达2014机器学习教程笔记目录
在Hexo中渲染MathJax数学公式
Linux服务器性能检测命令集锦
Redis开启AOF导致的删库事件
从表扩展增加列属性说起
数据库规约解读
MySQL规约(阿里巴巴)
HDFS运行原理
原文地址:https://www.cnblogs.com/DotNet1010/p/1154065.html
最新文章
kafka中的回调函数
Activation functions on the Keras
C# ArrayList、HashSet、HashTable、List、Dictionary的区别
string,const char*, char*转换之后还是指向同一片内存地址么?
字符串操作基础函数实现
请实现一个函数,将一个字符串中的每个空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。
Reverse array
Ruby中的self
基于c语言数据结构+严蔚敏——线性表章节源码,利用Codeblocks编译通过
ruby puts语法
热门文章
算法:二维数组中的查找
再读<<基于MVC的JavaScript Web 富应用开发>>
琐事一二三
ExtJS学习之路第八步:Window组件
ExtJS学习之路第七步:contentEl与renderTo的区别
ExtJS学习之路第六步:深入讨论组件Panel用法
ExtJS学习之路第五步:认识最常见组件Panel
ExtJS学习之路第四步:看源码,实战MessageBox
ExtJS学习之路第三步:理解引擎之下,ExtJS4中的类
ExtJS学习之路第二步:Ext.Component 和 Ext.dom.Element 的区别
Copyright © 2011-2022 走看看