asp.net - EF6: Enum Types -


there option in ef6 designer convert property enum type. used add new enum type model. how bind enum dropdownlist in formview?

note: i'm using web forms asp.net model binding.

enum.getvalues looking believe:

public enum currency {     usd = 0,     euro,     frank,     pound }  var listitems = new list<selectlistitem>(); foreach(currency c in enum.getvalues(typeof(currency))) {     listitems.add(new selectlistitem() { value = (int)c, text = c.tostring() }) } 

and bind listitems...

if deal different enums been presented via drop down controls, can implement generic method generates bindable datasource enum type based on following implementation of enumtolist method:

http://extensionmethod.net/csharp/enum/generic-enum-to-list-t-converter

public static list<selectlistitem> createselectlist<t>() {     var listitems = new list<selectlistitem>();     foreach(var e in enumtolist<t>())     {         listitems.add(new selectlistitem() { value = (int)e, text = e.tostring() })     }      return listitems } 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -