ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 21st, 2003, 01:23 AM
Tyssen Tyssen is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Brisbane
Posts: 129 Tyssen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 31 m 55 sec
Reputation Power: 6
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.

Reply With Quote
  #2  
Old November 21st, 2003, 06:01 AM
ShermanPeabody ShermanPeabody is offline
CDONT[RE:"member"]
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: United States
Posts: 35 ShermanPeabody User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 6 sec
Reputation Power: 6
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

Reply With Quote
  #3  
Old November 23rd, 2003, 05:22 PM
Tyssen Tyssen is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Brisbane
Posts: 129 Tyssen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 31 m 55 sec
Reputation Power: 6
Thumbs up

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

Reply With Quote
  #4  
Old November 23rd, 2003, 07:15 PM
unclefu unclefu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 120 unclefu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 57 sec
Reputation Power: 6
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.

Reply With Quote
  #5  
Old November 23rd, 2003, 07:26 PM
Tyssen Tyssen is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Brisbane
Posts: 129 Tyssen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 31 m 55 sec
Reputation Power: 6
Thumbs up

Excellent! That did it too. Thanks Unclefu!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Dynamic list population problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT