Put the enumerated binding server control and HTML control

xiaoxiao2021-03-06  52

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 /// /// listControl control /// enumeration type /// Add to the item in the first item (ListItem) 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 /// /// HTMLSELECT control /// enumeration type /// Add to the item in the first item (ListItem) 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 ()));}}

转载请注明原文地址:https://www.9cbs.com/read-115730.html

New Post(0)