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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get listbox items

Status
Not open for further replies.

Shift838

IS-IT--Management
Jan 27, 2003
987
US
How can I get listbox items from a listbox, row by row. so after it reads one row it assigns a value, etc.. I want a different value for each row it reads. I know how to count them, just not how to actually read the string that is in each row.
 
does a for loop over the items collection of the listbox not give you exactly that? what have you tried?

________________________________________
Andrew
 
I have not tried anything besides the lstbox.items.count

 
well, lstbox.items has far more than a count property, you should take a look at the .Item collection

________________________________________
Andrew
 
Ok, used the following code and it works:

Dim item As ListItem
For Each item In lstevent1.Items
lstevent2.Items.Add(item)
Next

my next questions is how would I for each it pulls assigne a different string variable to that item it has pulled

so say it pulls david and John, how could I assign it seperate string variables to david and john.
 
Check the properties of a ListItem, it also has several useful features. Check your documentation, all of these answers are there in a very straightforward manner.

________________________________________
Andrew
 
I can get it to assign to a string but when the page is posted back it foregets the previosu variable. I need it to remember all of them..
 
do you want 1 variable to hold all items or a different variable for each?
 
different variables for each. Each one will be written to a database at the end so I need one for each..unless the sql field can hold more than one and we can pull them out seprately some how.

What it is is a listbox that users can add other users to. It should go through the list box and assign each entry a string or if all of them can be sent to a sql field through one string that is fine if it is possible to pull them out and separate them later.
 
The problem with assigning them to separate variables is that you would have to know how many to declare, since you cannot dynamically declare variables.
I would take the second route and send one string to a stored procedure and pull them out one by one and do the insert.
 
Or why not just loop through the listbox items, and grab each value, then do the Insert.

For 1 = 1 to listbox.items.count
var = listbox.item(i).text

'run sql here...
Insert into <table>
Values (var)

Next
 
the database I have has varoius fields of e1attendee1 - 10, and e2attendee1 - 10, etc. how can I make the page write to the database for the fields without creating new record entries. do it on the same record, however if they come back later that day and register more users, to create a new record and not overwrite the other one...
 
I have to say this is bad DB design. I would seriously chaning the design to have a related table tha holds the atendee values. Doing it the current way can lead you into lots of "dirty" coding. Beleive me I know since I deal with a DB with similar problems you are describing. The problem is you have to have a column for each attendee. What if this amount changes? Then you have to add columns. And change multiple pages of code.
 
I think you are right.. I will create a different table to house what i need it to and make it more clean. so maybe have table that only has:

full name, event1, event2, event3

events are boolean values

so now I need to loop through the listbox and find the selected items and assign a boolean value and write that to the database. I beleive that will be much cleaner..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top