Solved

Populate DropDownList with IEnumerable

Posted on 2013-02-07
2
499 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
ID: 38867337
DropdownList.Datasource = GetProducts();
DropdownList.TextField = "Desc";
DropdownList.ValueField = "ID";
DropdownList.DataBind();

it will take respective values.
0
 

Author Comment

by:gogetsome
ID: 38867830
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

791 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