enum and dropdownlist

G

Guest

he yall,
does anyone know the best way to populate a dropdownlist from an enum list?

thanks,
rodchar
 
C

carion1

if (!IsPostBack)
{
ListItem li;

foreach (myEnum myValue in Enum.GetValues(typeof(myEnum)))
{
li = new ListItem(Enum.GetName(typeof(myEnum), myValue).ToString(),
myValue.ToString());
myDropDownList.Items.Add(li);
}
}

Derek
 
G

Guest

Thank you for that, ok now that the dropdownlist has the enums when the user
selects an item how do i convert it back to the enum type

when i try to assign the selected value back to the type:

_varType = DropDownList1.SelectValue;

I get an error message that says cannot convert type 'string' to type 'enum'.
 
C

carion1

What exactly are you trying to accomplish. A short but working
example of what you have so far would help greatly.

Derek
 
B

bruce barker

_varType = Enum.Parse(typeof(myEnum),DropDownList1.SelectValue);

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top