Solved

How do I retrieve an object from a listbox?

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

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
How to measure sizes and angles in scanned images ? 3 53
how to read json value 2 31
Reset asp.net login password 4 31
Coding C# in Linux 8 31
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…
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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

14 Experts available now in Live!

Get 1:1 Help Now