asp.net項(xiàng)目開發(fā)中枚舉的使用方法

asp.net項(xiàng)目開發(fā)中枚舉的使用方法?這個(gè)問題可能是我們?nèi)粘W(xué)習(xí)或工作經(jīng)常見到的。希望通過這個(gè)問題能讓你收獲頗深。下面是小編給大家?guī)淼膮⒖純?nèi)容,讓我們一起來看看吧!

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長期合作伙伴,公司提供的服務(wù)項(xiàng)目有:申請(qǐng)域名、網(wǎng)站空間、營銷軟件、網(wǎng)站建設(shè)、衛(wèi)東網(wǎng)站維護(hù)、網(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; 
}

感謝各位的閱讀!看完上述內(nèi)容,你們對(duì)asp.net項(xiàng)目開發(fā)中枚舉的使用方法大概了解了嗎?希望文章內(nèi)容對(duì)大家有所幫助。如果想了解更多相關(guān)文章內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

網(wǎng)頁名稱:asp.net項(xiàng)目開發(fā)中枚舉的使用方法
文章源于:http://bm7419.com/article34/jdsipe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、App開發(fā)、靜態(tài)網(wǎng)站網(wǎng)站策劃、網(wǎng)頁設(shè)計(jì)公司、

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名