asp.net項目開發(fā)中枚舉的使用方法?這個問題可能是我們日常學習或工作經(jīng)常見到的。希望通過這個問題能讓你收獲頗深。下面是小編給大家?guī)淼膮⒖純热荩屛覀円黄饋砜纯窗桑?/p>
讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領域值得信任、有價值的長期合作伙伴,公司提供的服務項目有:申請域名、網(wǎng)站空間、營銷軟件、網(wǎng)站建設、衛(wèi)東網(wǎng)站維護、網(wǎng)站推廣。
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項目開發(fā)中枚舉的使用方法大概了解了嗎?希望文章內容對大家有所幫助。如果想了解更多相關文章內容,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)頁名稱:asp.net項目開發(fā)中枚舉的使用方法
文章源于:http://m.2m8n56k.cn/article34/jdsipe.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、App開發(fā)、靜態(tài)網(wǎng)站、網(wǎng)站策劃、網(wǎng)頁設計公司、
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)