Solved

Populate DropDownList with IEnumerable

Posted on 2013-02-07
2
492 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

911 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

24 Experts available now in Live!

Get 1:1 Help Now