BIND ENUM to a dropdownlist

Madhu.b.rokkam
Posted by Madhu.b.rokkam under C# category on | Points: 40 | Views : 3773
We can bind the enum to a dropdown as follows

public enum Colors
{
Red = 1,
Orange = 2,
Green = 3,
Black = 4,
None = 0
}

and to add this to a dropdown you can do as on page load

foreach(int val in Enum.GetValues(typeof(Colors)))
{
ddlcolors.Items.Add(new ListItem(Enum.GetName(typeof(Colors), val)))
}

Comments or Responses

Login to post response