Click to See Complete Forum and Search --> : drop down box
vkallelil
Jun 19th, 2001, 06:11 AM
Can anybody help me.
1) I want to populate a drop down box from the result of a query.
I already have a recordset with the values that I needed. Now how can I link the drop down box to the recordset.
2) Then, I want to populate a second drop down box based on values selected from the first drop down box.
Reggie
JoshT
Jun 19th, 2001, 06:43 AM
Do While Not RS.EOF
Response.Write "<option>" & rs.fields("Whatever") & "</option>"
RS.MoveNext
Loop
vkallelil
Jun 19th, 2001, 07:57 AM
JoshT,
This is the code I wrote but it is not populating my drop down box. I can see the box but the box is empty. I know I have 5 values in my recordset.
What wrong with this piece of code:
<%
Response.Write "<br><Select Name=""cboSystem"" style=HEIGHT: 22px; WIDTH: 100px "&" >"
Do While Not Rec.EOF
Response.Write "<OPTION>" & Rec.Fields("LEGACY_SYSTEM_CD") & "</OPTION>"
Rec.MoveNext
loop
Response.Write "</SELECT><br>"
%>
JoshT
Jun 19th, 2001, 10:46 AM
Look at the source code for the generated page and make sure there's the 5 <option> tags from your recordset. If not, it's a problem with the rs. (And the box will be empty until you pick something from the list, unless there's one and only one option tag with the selected attribute).
vkallelil
Jun 19th, 2001, 01:19 PM
I have the same response.write code written outside the drop down box with a different do while loop and the results are
20
50
64
81
83
but my option box is blank. There is no values, nothing in there.
So my recordset looks good, but its not populating the drop down box.
Please help
Reggie
JoshT
Jun 19th, 2001, 02:01 PM
I bet its because your first loop moved the rs cursor to the end of the recordset and you never moved it back to the beginning (MoveFirst) of the recordset for the second loop. Make sure you're not opening it as Forward-Only.
vkallelil
Jun 19th, 2001, 02:16 PM
Sorry JoshT,
That's exactly what was happening.
Now, how can I populate the second combo box based on the value selected from the first combo box.
What is the best way of doing this. Do I have to submit the form to itself or is there another way.
Reggie
CiberTHuG
Jun 19th, 2001, 02:19 PM
Do you want the two combo boxes on the same page? You can do that with JavaScript (or some other client side script).
If the two combo boxes are on different pages, then you can pull the value from the Request.Form object. Though I don't remember how to do that for multiple selection combo boxes.
vkallelil
Jun 19th, 2001, 02:58 PM
Actually, what I want is 3 combo boxes on one page. The first combo box should populate based on a query.
The second combo box should be populated based on a query, for the value selected from combo box one.
And the third combo box should be populated based on a query, for the value selected from combo box two.
The reason why I want to do that way is, my first combo box is systems, second is division and third is products.
So, if the user selects a value from combo one (systems), he should only see the divisions (in the second combo box) that are applicable to value selected in the first combo box.
I hope I'm making some sense. I have this same application is VB, which works fine, but how can I write the same in ASP.:confused:
Reggie
CreoN
Jun 19th, 2001, 03:36 PM
Since an ASP-page only "runs" when it's loaded you can't change contents of a page using ASP.
The way you can do this is using JavaScript and loading all the different values into arrays. And using this choose what things to show in which combo boxes. As long as there isn't too many different values, this should be working just fine.
monte96
Jun 19th, 2001, 08:34 PM
Basically, you will create client side arrays using server side code and response.writes. With all the possible values. Another possibility is using client side XML, but be aware that using client side XML means IE only since you create an activeX instance of the XML parser.
vkallelil
Jun 20th, 2001, 03:17 PM
Thanks guys for all the input.
I tried design time controls and script to populate, and all my drop down list boxes are working fine.
This is the script I used:
Sub thisPage_onenter()
If thispage.firstEntered Then
Recordset1.open
End if
End Sub
Sub Listbox1_onchange()
FillListbox2
End Sub
Sub Recordset1_ondatasetcomplete()
FillListbox2
End Sub
Sub FillListbox2
Listbox2.clear
If Recordset2.isOpen() Then
Recordset2.close
End if
sql="Select LEGACY_DIVISION_CD from pend_monthly_qinventory " & _
"Where LEGACY_SYSTEM_CD = '" & Listbox1.getValue(Listbox1.selectedIndex) & "' " & _
"group by LEGACY_DIVISION_CD "
Recordset2.setSQLText(sql)
Recordset2.open
End Sub
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.