Solved

Populate a listbox from a class list C#

Posted on 2013-12-10
2
452 Views
Last Modified: 2013-12-11
I have created a class to populate a list with values from the database.

I would like to reference this class to load values into a listbox.

I have attached what I have so far.

Could you please tell me how I could load value into my list box which is ListBox1, see attachement.
populate-list-box.txt
0
Comment
Question by:cookiejar
2 Comments
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 39710520
Try something like:

ListBox1.DataSource = MyClassList;;; the list you got from database
// here you may try to set DataValueField and DataTextField, e.g.:
ListBox1.DataTextField = "Partnumber";
ListBox1.DataBind();

Open in new window

0
 
LVL 12

Accepted Solution

by:
Jitendra Patil earned 500 total points
ID: 39711051
hi
according to your attachment, it seems your are trying to get all spareparts in the list.

so first of all you need to create a instance of the class you want to refer. say

Class C= new  Class();// after creating instance of the class you will be able to acess all its methods and functions.  say

C.GetAllparts()// now the get all parts function returns Dataset you need to declare a blank dataset and assing the dataset value as below.

DataSet Ds= new DataSet;
Ds=C.GetAllParts();

Open in new window


now your dataset will be filled by the data you need and you can bind your list as below.
Listbox1.DataSource=Ds.tables["your table name" OR index of table];
Listbox1.Databind();

Open in new window


hope this helps.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

21 Experts available now in Live!

Get 1:1 Help Now