Solved

Populate a listbox from a class list C#

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Json and asp.net mvc 2 44
Error in JQuery 5 36
ASP.net Run 3 sliders vertically as opposed to horizontally 9 18
Close form "before" open 3 19
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

13 Experts available now in Live!

Get 1:1 Help Now