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();
查看全文
相关阅读:
在ubuntu上搭建开发环境9---Ubuntu删除ibus出现的问题及解决
在ubuntu上搭建开发环境8---Ubuntu搭建Android开发环境
在ubuntu上搭建开发环境7---ubuntu安装JDK
在ubuntu上搭建开发环境6---安装和使用vim及其插件(Pathogen和NERDTree)
在ubuntu上搭建开发环境5---联想Y470安装 ubuntu,解决双显卡发热等问题
在ubuntu上搭建开发环境4---ubuntu简单的搭建LAMP环境和配置
在ubuntu上搭建开发环境3---解决Y470一键系统重装之后恢复ubuntu引导启动的方法
在ubuntu上搭建开发环境2---Win7、Ubuntu双系统正确删除Ubuntu
在ubuntu上搭建开发环境1---在windows7的基础上在安装ubuntu(双系统)
单例模式的七种写法
原文地址:https://www.cnblogs.com/DotNet1010/p/1154065.html
最新文章
centos7修改root根目录
【转】PHP实现验证码
centos7 虚拟机安装docker-ce-17.09
centos7 安装网卡
谷歌开源OCR,tesseract-ocr使用笔记
C#.Net Core 操作Docker中的redis数据库
使用ES6新数组方法(象C# Lambda表达式一样写查询语句)
Angular学习第一步
Docker入门记
在Visual Studio 2017中安装bower
热门文章
C#字符串分割成列表及相反转换
JavaScript之radio遍历
ABP默认生成数据库结构
Linux常用命令学习1---(安装、文件系统、目录操作命令cd ls mv cp rm mkdir、链接命令ln……)
Linux文件系统(inode、block……)
Oracle如何写出高效的SQL
SQL小纸条--一些方便平时参考的SQL语句--随用随查
Delphi中的函数指针判断是否为空
Delphi中的异常处理
在ubuntu上搭建开发环境10---英文版ubuntu安装中文输入法
Copyright © 2011-2022 走看看