c# - Bind enum to AspxListBox -
i have following enum
called billtypes
:
public enum billtypes { [enumproperties("natural gas")] naturalgas= 1, [enumproperties("electric")] electric = 2, [enumproperties("water")] water = 3 }
how can bind enum
aspxlistbox
?
i think should able run following: (please bear me, if code not work, due i'm not familar asp
)
billtypes b = billtypes.electric; aspxlistbox alb = new aspxlistbox(); alb.items.add(billtypes.natural_gas.tostring().replace("_", " ")); alb.items.add(billtypes.electric.tostring().replace("_", " ")); alb.items.add(billtypes.water.tostring().replace("_", " ")); alb.selectedindexchanged += (ob, ex) => (indexchanged());
and method indexchanged
:
public void indexchanged() { b = (billtypes)(alb.selectedindex + 1); // here can whatever want... }
note edited enum
class:
public enum billtypes { [enumproperties("natural gas")] natural_gas= 1, [enumproperties("electric")] electric = 2, [enumproperties("water")] water = 3 }
after can handle every code use, according variable billtypes
b
.
Comments
Post a Comment