Welcome to Dukebaby Sign in | Join | Help

Get Enum by value in C#

This is mainly for my own reference since I find myself looking this up now and then.

Lets say I have a dropdownlist of enum items where the ddl value is equal to the enum value.  So, when when ddl item is selected now you want to get the actual enum represented by this.

I have found this to work where EnumItems is the name of the enum:

EnumItems enumItem = (EnumItems)Enum.Parse(typeof(EnumItems), ddl.SelectedValue);

 

Published Friday, August 31, 2007 4:26 AM by dukebaby
Filed under: ,

Comments

Anonymous comments are disabled