手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >asp.net项目开发中用到的小技巧
asp.net项目开发中用到的小技巧
摘要:1显示枚举的值:2为下拉框绑定枚举:复制代码代码如下:GetEnumList(ddlBids);voidGetEnumList(DropDo...

1 显示枚举的值:<%# (CN80s.DDPM.Model.Enum.EnumBidCardStatus)(int)Eval("PerpaidCard_Status")%>

2 为下拉框绑定枚举:

复制代码 代码如下:

GetEnumList(ddlBids);

void GetEnumList(DropDownList ddl)

{

foreach (EnumBidCardType s in System.Enum.GetValues(typeof(EnumBidCardType)))

{

ddl.Items.Add(new ListItem(s.ToString(), ((int)s).ToString()));

}

}

this.ddlBids.DataSource = GetEnumList(typeof(EnumBidCardType), true);

this.ddlBids.DataTextField = "Text";

this.ddlBids.DataValueField = "Value";

this.ddlBids.DataBind();

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;

}

【asp.net项目开发中用到的小技巧】相关文章:

ASP.NET中的URL映射技巧

如何为asp.net网站项目添加子项目

asp.net 票据简单应用

asp.NET开发中正则表达式中BUG分析

asp.net小孔子cms中的数据添加修改

ASP.NET编程中的十大技巧第1/2页

asp.net中利用ashx实现图片防盗链的原理分析

asp.net下百度的编码和解码

asp.net UpdatePanel的简单用法

asp.net下url传递中文的解决方案

精品推荐
分类导航