Solved

How do I retrieve an object from a listbox?

Posted on 2004-08-31
2
297 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 500 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
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!
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

626 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