c# - Retrieving drop down list items from list of controls -


i attempting retrieve listitemcollection list of controls. list contains many controls of different types - dropdownlist, label, textbox.

i retrieve listitem dropdownlist controls contained in original list of controls.

my thought process far has been extract of dropdownlist controls new list, , iterate though pull out each listitem - however, every dropdownlist control coming 0 items

controlcollection clist = pnlcontent.controls;  list<dropdownlist> ddllist = new list<dropdownlist>(); foreach (control c in clist) {     if (c.gettype() == new dropdownlist().gettype())     {         ddllist.add((dropdownlist)c);     } }  listitemcollection itemcollection = new listitemcollection(); foreach (dropdownlist ddl in ddllist) {     foreach(listitem li in ddl.items)     {         itemcollection.add(li);     } } 

i'm sure wrong (and massively inefficient) way of doing this. appreciated.

this do:

public ienumerable<listitem> getlistitems(controlcollection controls) {     return controls.oftype<dropdownlist>().selectmany(c => c.items.oftype<listitem>()); } 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -