1. display the enumerated values: <% # (CN80s. DDPM. Model. Enum. EnumBidCardStatus) (int) Eval ("PerpaidCard_Status") %>
2. bind an enumeration to the drop-down box:
Copy codeThe Code is 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;
}