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 29th, 2003, 07:48 AM
sullypandor sullypandor is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 2 sullypandor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Dropw down list

Help

Scenario is this:

User selects Product #1 to update, this takes him to a form which populates fields for that particular product. i.e product name, price etc (from products table)

This page should also have a dropdown list for the categories (popluated from the categories table) but I want the category for the chosen product to be selected by default. (i hope its clear)

eg if user selects jaguar XK8 to update, the relevant category that should be selected should be sports car (but the dropdown list should also display the rest of the categories (luxury, economy etc)

below is my sql query

strSQL1 = "SELECT tblProducts.PID, tblCategory.Category, tblCategory.CategoryID " &_
"FROM tblCategory INNER JOIN tblProducts ON tblCategory.Category = tblProducts.Category"

and then my scrip to populate the dropw down list:
<%
Response.Write "<SELECT Name=""Category"">"
Response.Write "<OPTION Value="" ""></OPTION>"

' Loop through the recordset and populate the dropdown
while not objRS1.eof
if objRS1.fields("CategoryID") = selected then
response.write("<OPTION VALUE=" & objRS1.fields("CategoryID") & " selected>")
response.write(objRS1.fields("Category") & "</OPTION>")
else
response.write("<OPTION VALUE=" & objRS1.fields("CategoryID") & ">")
response.write(objRS1.fields("Category") & "</OPTION>")
end if
objRS1.MoveNext
wend

'Close the Selection box
Response.write "</select>"

%>

Reply With Quote
  #2  
Old December 2nd, 2003, 09:56 AM
bramsey bramsey is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Location: USA
Posts: 226 bramsey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 40 m 35 sec
Reputation Power: 9
Compare objRS1.fields("Category") to the form selction. If they are the same, add selected to the option. You can do it with a simple if statement in your code.

Reply With Quote
  #3  
Old December 2nd, 2003, 01:52 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
what you want to do is a query statement to lookup all the information on the product - store that info in local variables, so lets say your Category ID is 5 for "Sports Car"

so in your while not loop you simply place
Code:
'code to lookup product info here
categoryId = rs("categoryId") 'category to which the product is already assigned

'code to get recordset of all categories here

while not objRS1.eof
if objRS1.fields("CategoryID") = categoryId then
     response.write( "<OPTION VALUE=" & objRS1.fields("CategoryID") & " selected>" & objRS1.fields("Category") & "</OPTION>")
else
     response.write( "<OPTION VALUE=" & objRS1.fields("CategoryID") & ">" & objRS1.fields("Category") & "</OPTION>")
end if
objRS1.MoveNext
wend

'rest of your code here
%>

Reply With Quote
  #4  
Old December 2nd, 2003, 07:25 PM
pda8333 pda8333 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 216 pda8333 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 6 m 31 sec
Reputation Power: 6
another shorter way would be:
Code:
while not objRS1.eof
     response.write( "<OPTION VALUE=" & objRS1.fields("CategoryID") & " <%if objRS1.fields("CategoryID") = categoryId then%>selected<%end if%>>" & objRS1.fields("Category") & "</OPTION>")
objRS1.MoveNext
wend
__________________
Hope this helps.

Mike
Royal Selangor Pewter

"I have not failed. I've just found 10,000 ways that won't work."
- Thomas Alva Edison (1847-1931)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Dropw down list


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


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





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