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

Use Server.Execute to fill combo box 1

Status
Not open for further replies.

rtshort

IS-IT--Management
Feb 28, 2001
878
US
I am trying to use Server.Execute to fill a combo box. I use it on the first asp page as follows:

Sub cboTest1_Change
frmTest2.cboTest2.AddItem &quot;<%Server.Execute (&quot;FillEngMake.asp&quot;)%>&quot;
End Sub

The FillEngMake.asp page is as follows:

<%@ Language=VBScript %>
<%Dim cnEngMake, rsEngMake, sqlEngMake, EngMake%>

<%
Set cnEngMake = Server.CreateObject(&quot;ADODB.Connection&quot;)
Set rsEngMake = Server.CreateObject(&quot;ADODB.RecordSet&quot;)
cnEngMake.ConnectionString = &quot;Driver=SQL Server;uid=;pwd=;Server=Server;Database=DB&quot;
cnEngMake.Open
sqlEngMake = &quot;Select Make from EngMake Order by Make&quot;
rsEngMake.Open sqlEngMake, cnEngMake, 3, 3
If Not rsEngMake.BOF and Not rsEngMake.EOF Then
rsEngMake.MoveFirst
Do Until rsEngMake.EOF = True
EngMake = rsEngMake.Fields(&quot;Make&quot;)
rsEngMake.MoveNext
Response.Write (EngMake & &quot;<br>&quot;)
Loop
Else
Response.Write (&quot;No Record Found&quot;)
End If
rsEngMake.Close
Set rsEngMake = Nothing
cnEngMake.Close
Set cnEngMake = Nothing
%>

This gets the information I need in cboTest2, but it is on the same line like this:
Chrysler<br>Mariner<br>Mercury<br>...etc.
I of course need it to be on multiple lines like this:
Chrysler
Mariner
Mercury
...etc.

If I access the page directly, because of the <br> tag, it shows up correctly. This obviously won't work filling the combo box.

What do I need to do to get the information on seperate lines like a combo box should be? Rob
Just my $.02.
 
Hi ...
in the FillEngMake.asp
instead of
Response.Write (EngMake & &quot;<br>&quot;)
you can use
Response.Write (EngMake & VbCrLf)
----
TNX.
E.T.
 
The reason it's all showing up on one line is because you are only adding one item. Since the FillEngMake is running server side, but the cbo_Test1 is running client side, if you look at your source you will notice that you end up with a client-side code that looks like:
Code:
Sub cboTest1_Change
frmTest2.cboTest2.AddItem &quot;Chrysler<br>Mariner<br>Mercury<br>&quot;
End Sub
This obviously doesn't work. What you will need to do is either make your FillEngMake function response.write frmTest2.cboTest2.AddItem in front of each item (without br tags) or just build the combo box in a standard loop outputting option tags in your select box.

It appears that you are trying to run this client-side, perhaps after someone chooses a selection from one box you are filling in another. The problem here is that no matter what they choose from the first box, the second box will always display the same things as it is be done on the server side before the user even sees the page. Ignore this paragraph if I am way off here :)

-Tarwn The three most dangerous things in the world are a programmer with a soldering iron, a hardware type with a program patch, and a user with an idea
-computer saying (Wiz Biz - Rick Cook)
 
I've tried the vbCrLf. It still puts it on the same line.
I'll give that a shot Tarwn and see what happens. Sounds good though. Rob
Just my $.02.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top