How to Loop IEnumerable ..

  • Thread starter Thread starter Praveen
  • Start date Start date
P

Praveen

I am creating a custom dropdownList control. The control
exposes a property named "DataSource".
Now the DataSource can be anything like a DataTable,
ArrayList, Array etc. While adding the Items to the
DropDownList Control how to handle all these different
DataSources. I have read it somewhere that it can be done
through IEnumerable.
I have add the ItemValue and ItemText to the dropdown. But
how to loop through a IEnumerable?

Any suggestion are appreciated.

Thanks
Modi.net
 
Hi,

if I understand your problem correctly you want to know how to bind a
DropDownList control
to a collection. The point is that you can simply set the DataSource
property of the DropDownList
to a DataTable, ArrayList, or any other collection of your choice. There is
no data source there that
you have to add your entries to.

Example (untested):

string[] myItems = new string[] { "one", "two", "three" };
dropDownList.DataSource = myItems;
dropDownList.DataBind();

Hope that helps. Sorry, if I misunderstood your question.

- Dennis
 
Back
Top