Example introduction to the use of enumerations in ASP. NET project development

Source: Internet
Author: User
This article introduces the use of enumerations in the development of ASP. Contains an enumeration of the values that display the enumeration and an example description of the two functions enumerated for the drop-down box binding.

1 Displays the value of the enumeration: <%# (CN80s.DDPM.Model.Enum.EnumBidCardStatus) (int) Eval ("Perpaidcard_status")%>
2 binding Enumerations for drop-down boxes:

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 ("--All--", ""));} Type typedescription = typeof (DescriptionAttribute); system.reflection.fieldinfo[] fields = Enumtype.getfields (); String strText = String. Empty; String strvalue = String. Empty; foreach (FieldInfo field) {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; }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.