?
Solved

Populate a listbox from a class list C#

Posted on 2013-12-10
2
Medium Priority
?
512 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 30

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 13

Accepted Solution

by:
Jitendra Patil earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

770 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