Solved

Populate a listbox from a class list C#

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
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…

774 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