For training related to .net,OOPS,design patterns, MVC,WCF and .net fundamentals
contact at sukeshmarla@gmail.com or Click Here

Click here for my training feedbacks

Followers

Follow Us



Share your Interview questions here


For software development queries contact SukeshMarla@Gmail.com

Follow by Email

Learn everything about MSBI

06 May 2011

Bind Enum to a DropDown

So, you have an enum defined as follows:
public enum Gender
{
        Male= 0,
        Female= 1
}
Code to Bind the Dropdown
string[] names = Enum.GetNames(typeof(Gender));
var values = (Gender[])Enum.GetValues(typeof(Gender));
for (int i = 0; i < names.Length; i++)
{
      DdlGender.Items.Add(new ListItem(names[i], values[i].ToString()));
}