Sometimes, we have to use the same DropDownList or RadiobuttonList or CheckBoxList control in many places, then we can use the enumeration type. The benefit of this is to facilitate code maintenance.
Use example:
Public class config {public enum enum_shoestype {adhesive shoes, shoes, outer flashes, sulfide shoes, injection shoes, 头 进 法, machine car bottom method, bag shoes, drainage, external seam, other systems } Public config () {}}
BindlistControlbyenum (DropDownList1, Typeof (config.enum_shoestype), New ListItem ("Please select", "-1"));
/// /// Binding control /// summary> /// listControl control param> /// enumeration type param> /// Add to the item in the first item (ListItem) param> public static void bindlistControlbyenum (System.Web.ui.WebControls.ListControl LC, System.Type Enumtype, System.Web.ui.WebControls.ListItem Li) {lc.items.clear (); lc.items.add (li); foreach (Object Obj in system.enum.getvalues) {lc.items. Add (new system.web.ui.webcontrols.listitem (obj.tostring (), ((int) OBJ) .tostring ()));}}
When binding to an HTML control, you must add Runat = "Server" to the HTML control.
/// /// Binding control /// summary> /// HTMLSELECT control param> /// enumeration type parame> /// Add to the item in the first item (ListItem) param> public static void bindlistControlbyenum (System.Web.ui.htmlControls.htmlselect HS, System.Type Enumtype, System.Web.ui.WebControls.listItem Li) {hs.Items.clear (); hs.items.add (li); foreach (Object Obj in system.enum.getvalues) {hs.Items. Add (new system.web.ui.webcontrols.listitem (obj.tostring (), ((int) OBJ) .tostring ()));}}