asp.net项目开发中用到的小技巧

小鱼们欢快的闹腾起来,有的甩动着尾巴,有的吐着泡泡,有的扭动着身体,互相追玩,好不热闹。春天来了!你看,融化的冰水把小溪弄醒了。 "丁粳、丁粳 ",它就像大自然的神奇歌手,唱着清脆悦耳的歌,向前奔流……
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项目开发中用到的小技巧内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!

您可能有感兴趣的文章
.NET Core 2.0迁移小技巧之web.config 配置文件示例详解

.NET Core 2.0迁移小技巧之MemoryCache问题修复解决的方法

ASP.NET常用小技巧

asp.net中Null在从数据库读取的时候的一点点小技巧

ASP.NET 后台登录小技巧介绍