Solved

How do I retrieve an object from a listbox?

Posted on 2004-08-31
2
260 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
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

20 Experts available now in Live!

Get 1:1 Help Now