国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net項(xiàng)目開發(fā)中用到的小技巧

2024-07-10 13:26:16
字體:
供稿:網(wǎng)友
1 顯示枚舉的值:<%# (CN80s.DDPM.Model.Enum.EnumBidCardStatus)(int)Eval("PerpaidCard_Status")%>
2 為下拉框綁定枚舉:

復(fù)制代碼 代碼如下:


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;
}

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 宣化县| 万山特区| 连城县| 玉树县| 平舆县| 五寨县| 正镶白旗| 嘉善县| 日土县| 图木舒克市| 涡阳县| 香格里拉县| 河北区| 武鸣县| 华蓥市| 攀枝花市| 洛浦县| 蒙自县| 滕州市| 新野县| 宿迁市| 苏尼特右旗| 山阳县| 望江县| 刚察县| 泸溪县| 山西省| 浦县| 甘谷县| 连山| 文化| 大港区| 宁武县| 黄大仙区| 安庆市| 浦江县| 道真| 哈尔滨市| 家居| 桦川县| 宜宾市|