您好,登錄后才能下訂單哦!
asp.net項(xiàng)目開發(fā)中枚舉的使用方法?這個(gè)問(wèn)題可能是我們?nèi)粘W(xué)習(xí)或工作經(jīng)常見(jiàn)到的。希望通過(guò)這個(gè)問(wèn)題能讓你收獲頗深。下面是小編給大家?guī)?lái)的參考內(nèi)容,讓我們一起來(lái)看看吧!
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; }
感謝各位的閱讀!看完上述內(nèi)容,你們對(duì)asp.net項(xiàng)目開發(fā)中枚舉的使用方法大概了解了嗎?希望文章內(nèi)容對(duì)大家有所幫助。如果想了解更多相關(guān)文章內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。