Solved

Populate DropDownList with IEnumerable

Posted on 2013-02-07
2
489 Views
Last Modified: 2013-02-11
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?
0
Comment
Question by:gogetsome
2 Comments
 
LVL 4

Accepted Solution

by:
Srinivasulu Muppala earned 500 total points
Comment Utility
DropdownList.Datasource = GetProducts();
DropdownList.TextField = "Desc";
DropdownList.ValueField = "ID";
DropdownList.DataBind();

it will take respective values.
0
 

Author Comment

by:gogetsome
Comment Utility
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"
DropdownList.DataBind()

Thanks again!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now