Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get list box items value in loop

Status
Not open for further replies.

Shift838

IS-IT--Management
Jan 27, 2003
987
US
I am wanting to get the list box items values and add them to a database. I have not been able to get it to work. I am trying:

dim x, y as integer
x = lstchoices.items.count

for y = 1 to x
lblstatus &= lstchoices.items.item(y).text
next y

this does not work though. Any thoughts?
 
If you are trying to see all the values when you loop, your code won't work. You will only see the last item in the label. Use a response.write to see all the values.


Jim
 
also, i believe you'd want to loop for y = 0 through x - 1...

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
You shouldn't really use integers to loop through list items if you can help it. Try using this instead:
Code:
        Dim sb As New StringBuilder
        For Each lst As ListItem In ListBox1.Items
            sb.Append(lst.Text)
        Next
        Response.Write(sb.ToString)



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Code:
For Each lst As ListItem In ListBox1.Items

I never knew about the "As ListItem" part. lol cool

I always did:
Code:
Dim lst as ListItem
For each lst in....

thanks ca8msm

-FD


 
No probs...there's loads of shortcuts like this; it's just finding them that's the problem!


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top