Populate DropDownList with IEnumerable

Hello I need help with the following scenario...
Given a class called Product with a shared method GetProducts() that returns an IEnumerable collection of Product objects with the properties ID and Desc, how would you populate a drop down list?
Who is Participating?
Srinivasulu MuppalaConnect With a Mentor Lead DeveloperCommented:
DropdownList.Datasource = GetProducts();
DropdownList.TextField = "Desc";
DropdownList.ValueField = "ID";

it will take respective values.
gogetsomeAuthor Commented:
Hello, thank you for your help!

I have never worked with an IEnumerable collection of objects. From your post I gather it binds to the DDL just like any other call to get data like this for example:

Dim Products As IList = ProductManager.GetProducts
DropdownList.Datasource = Products
DropdownList.TextField = "Desc"
DropdownList.ValueField = "ID"

Thanks again!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.