We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

EASY - Bind a list box to a dataset - how to

paygo
paygo asked
on
Medium Priority
162 Views
Last Modified: 2010-05-01
Hello All,

Does anyone know how to bind a dataset to an asp listbox:

I have a dataset - which is a list of counties.
I need to dynamically drop the contents of the dataset (its only one column - "county")into the listbox
here a start and thanks for the help as always.

This is not working

 listBoxCounty.DataSource = dataSet
 listBoxCounty.DataMember = "County"
 listBoxCounty.DataTextField = "County"
 listBoxCounty.DataValueField = "County"
 listBoxCounty.DataBind()






Comment
Watch Question

Carl TawnSenior Systems and Integration Developer
CERTIFIED EXPERT
Commented:
Try:

 listBoxCounty.DataSource = dataSet.Tables(0)
 listBoxCounty.DataMember = "County"
 listBoxCounty.DataTextField = "County"
 listBoxCounty.DataValueField = "County"
 listBoxCounty.DataBind()

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Director, IT and Business Development
Commented:
Try

lstReports.DataBindings.Clear()
lstReports.ValueMember = "ReportsKey"
lstReports.DataSource = dsDataSet.Tables("Reports")
lstReports.DisplayMember = "ReportDescription"

Note: the order in which these are executed is also important

Cheers,

Leo
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.