Create Drop Down List Options From Enum

Posted By Venu Thomas

To view the values of an enumeration’s type (enum) to a DropdownList (or other controls with a DataSource property available) is sufficient to bind the following code:

Here’s an example with its own enum (of course also works with system types)

?View Code CSHARP
public enum CountryList
{
Germany = 1,
India = 2,
Japan = 3,
UAE = 4,
USA = 5
}
 
DropdownList1.DataSource = System.Enum.GetValues(typeof(CountryList));

Now, whenever you want to get to The Value of Even enum () method of the enum is useful to get under the VALUE of enum sees below snippet will helpful to
you.

?View Code CSHARP
int intCountry = Convert.ToInt32(System.Enum.Parse(typeof(CountryList), DropdownList1.SelectedItem.ToString());

Read More…

Happy Programming!!

Tags: , , ,

  •  
  • Share with others:

    Thanks for visiting us! If you enjoyed these icons please feel free to share them! Or if you want to know what's going on with WiseCodes.com, follow us!

    Leave a Reply

    Anti-Spam Protection by WP-SpamFree

    Locations of visitors to this page eXTReMe Tracker