1 Displays the value of the enumeration: <%# (CN80s.DDPM.Model.Enum.EnumBidCardStatus) (int) Eval ("Perpaidcard_status")%>
2 for the Drop-down box to bind the enumeration:
Copy Code code as follows:
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 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;
}