Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I retrieve an object from a listbox?

Posted on 2004-08-31
2
Medium Priority
?
299 Views
Last Modified: 2010-04-15
Hi,

I CAN get the selected item from a listbox without a problem.  But I'm having trouble
when I want to get the first item or the second.  There are so many methods, yet I can't seem to find the one that's right for me.  The content is a string and I'd just like to retrive the string, one by one, for the entir list.

It would be a big help to me if I could solve this ASAP.

Thanks.
0
Comment
Question by:ba272
[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 10

Accepted Solution

by:
123654789987 earned 2000 total points
ID: 11939937
There is a property for a listbox called datasource. U can use it

listbox1.dataSource = dataTable

Then loop through the datatable.U should know the column of the datatable that is mapped to the listbox. Eg:If it is column called "first"

for(int i=0;i<=datatable.rows.count -1;i++)
{
  string str = datatable[i]["first"];
}
0
 
LVL 2

Expert Comment

by:Daeljan
ID: 11940026
How about trying this:

ListBox lb = new System.Web.UI.WebControls.ListBox();

// Databind the list here

// Examine the list as below:
foreach (ListItem item in lb.Items)
{
  // Here there is read and write access to the following properties
  item.Text = "Text value";
  item.Value = "Value value";
}
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

670 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