c# - How do you bind an Enum to a DropDownList control in ASP.NET? -


let's have following simple enum:

enum response {     yes = 1,     no = 2,     maybe = 3 } 

how can bind enum dropdownlist control descriptions displayed in list retrieve associated numeric value (1,2,3) once option has been selected?

i wouldn't bind data it's enum, , won't change after compile time (unless i'm having 1 of stoopid moments).

better iterate through enum:

dim itemvalues array = system.enum.getvalues(gettype(response)) dim itemnames array = system.enum.getnames(gettype(response))  integer = 0 itemnames.length - 1     dim item new listitem(itemnames(i), itemvalues(i))     dropdownlist.items.add(item) next 

or same in c#

array itemvalues = system.enum.getvalues(typeof(response)); array itemnames = system.enum.getnames(typeof(response));  (int = 0; <= itemnames.length - 1 ; i++) {     listitem item = new listitem(itemnames[i], itemvalues[i]);     dropdownlist.items.add(item); } 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -