Populate an ASP.net ListBox with the values of an enumeration
Kind of like: Obtaining the string value of an enumeration name (but not).
public void PopulateListBoxFromEnum(DropDownList listBox, Type enumeration)
{
string[] descriptiveValues = Enum.GetNames(enumeration);
foreach (string descriptiveValue in descriptiveValues)
{
int statusValue = Convert.ToInt32(Enum.Parse(enumeration, descriptiveValue, true));
listBox.Items.Add(new ListItem(descriptiveValue, statusValue.ToString()));
}
}
Not a lot more to say really, other than, see above ;-)
public void PopulateListBoxFromEnum(DropDownList listBox, Type enumeration)
{
string[] descriptiveValues = Enum.GetNames(enumeration);
foreach (string descriptiveValue in descriptiveValues)
{
int statusValue = Convert.ToInt32(Enum.Parse(enumeration, descriptiveValue, true));
listBox.Items.Add(new ListItem(descriptiveValue, statusValue.ToString()));
}
}
Not a lot more to say really, other than, see above ;-)
