Solved

Populate a listbox from a class list C#

Posted on 2013-12-10
2
480 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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…

789 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