|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Dynamic list population problem
Can anyone see what I'm doing wrong here. I have a series of dropdown boxes on my site which are generated from the database which work fine, but when I go to modify the code for list boxes (multiple select), it doesn't work and I can't figure out why it wouldn't work.
Code:
Set suppRs = Server.CreateObject("ADODB.Recordset")
suppSQL = "SELECT * FROM suppliers"
Set suppRs = conn.execute(suppSQL)
suppArray = split(supp, ", ", -1, 1)
for iLoop = LBound(suppArray) to UBound(suppArray)
response.write(suppArray(iLoop))
response.write("<br>")
WHILE NOT suppRs.EOF
if suppArray(iLoop) = suppRs("ID") then
response.write(suppArray(iLoop))
strSupp = strSupp & "<option selected value=" & suppRs("ID") & ">" & suppRs("suppName") & "</option>"
else
strSupp = strSupp & "<option value=" & suppRs("ID") & ">" & suppRs("suppName") & "</option>"
end if
suppRs.MoveNext
WEND
next
suppRs.Close
The first response.write after the iLoop prints out the right numbers, so why is it that Code:
if suppArray(iLoop) = suppRs("ID") then
response.write(suppArray(iLoop))
doesn't give me anything? The response.writes are just there for testing purposes - the listbox prints out using the else part of the if statement, ie strSupp = strSupp & etc with no items selected. |
|
#2
|
|||
|
|||
|
Am I right that the
if suppArray(iLoop) = suppRs("ID") then ... else ... end if is skipping straight to the else? If so try converting the elements of the array back into integers or whatever they may be. if cInt(suppArray(iLoop)) = suppRs("ID") then I pretty sure it's 'cInt' I dont have any referance material with me right now. When you split them into the array they are string values so you can print them and they appear right, but they don't equal the int value. Sherman Peabody |
|
#3
|
|||
|
|||
|
Thanks Sherman, the cInt did it!
The only problem I have now is using this: Code:
WHILE NOT suppRs.EOF
for iLoop = LBound(suppArray) to UBound(suppArray)
if cInt(suppArray(iLoop)) = suppRs("ID") then
strSupp = strSupp & "<option selected value=" & suppRs("ID") & ">" & suppRs("suppName") & "</option>"
end if
next
strSupp = strSupp & "<option value=" & suppRs("ID") & ">" & suppRs("suppName") & "</option>"
suppRs.MoveNext
WEND
My list prints out two each of the items which match the recordset - one highlighted and one not highlighted. All the other items in the list appear not highlighted e.g. Item A Item A Item B Item B Item C Item D |
|
#4
|
|||
|
|||
|
a quick fix would be to use a boolean variable that starts false and if a match is found is set to true - then after the comparison loop (your for/next loop) it checks to see if that a match was found... if it wasn't then it just sets the var to a normal <option> tag instead of a selected one.
Code:
WHILE NOT suppRs.EOF
match = false
for iLoop = LBound(suppArray) to UBound(suppArray)
if cInt(suppArray(iLoop)) = suppRs("ID") then
strSupp = strSupp & "<option selected value=" & suppRs("ID") & ">" & suppRs("suppName") & "</option>"
match = true
end if
next
if match = false then
strSupp = strSupp & "<option value=" & suppRs("ID") & ">" & suppRs("suppName") & "</option>"
end if
suppRs.MoveNext
WEND
Last edited by unclefu : November 23rd, 2003 at 07:18 PM. |
|
#5
|
|||
|
|||
|
Excellent! That did it too. Thanks Unclefu!
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Dynamic list population problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|