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();
查看全文
相关阅读:
[Unity3D]查看与设置游戏帧数FPS
[Unity3D]关于NaN(Not a Number)的问题
Unity3D在WebPlayer模式下的异常上报探索
.net错误处理机制
.Net 下未捕获异常的处理
Appstore 提交时错误
播放器设置 Player Settings
(转)WebApi发送HTML表单数据:文件上传与多部分MIME
(转)那些年我们一起清除过的浮动
AppCan上下拉列表刷新
原文地址:https://www.cnblogs.com/DotNet1010/p/1154065.html
最新文章
F5设备控制脚本
技术走向管理一些思考(4)-怎样建设团队
基于ActiveMQ的消息中间件系统逻辑与物理架构设计具体解释
redis之Hash存储与String存储内存消耗对照
HDU 1576 A/B(扩展欧几里德变形)
SVNserver搭建和使用(二)
Leetcode 贪心 Best Time to Buy and Sell Stock
HDU-5310-Souvenir(C++ && 简单数学题)
<LeetCode OJ> 31. Next Permutation
angularJS批量删除 品优购删除品牌(通用复选框批量选中删除解决思路)
热门文章
mybatis 打印SQL语句
mybatis 根据id批量删除的两种方法
angularJS修改 品优购修改品牌(新增和修改用同一个方法)
angularJS新增 品优购新增品牌
JSON 与 对象 、集合 之间的转换
js ajax向后台传数组可以直接拼接传输
mybatis Mapper 中resultType使用方法及返回值为Map的写法
关于Mybatis的@Param注解 及 mybatis Mapper中各种传递参数的方法
mybaties实体的 Mapper.xml文件中自定义sql时模糊查询的写法
[Unity3D]UI方案及制作细节(NGUI/EZGUI/原生UI系统)
Copyright © 2011-2022 走看看