Groups | Blog | Home
all groups > inetserver asp db > august 2007 >

inetserver asp db : Still Not Resolved


Jack
8/22/2007 8:40:04 AM
Hi,
I want to display two fiels from a query in a combo box. I am checking to
make sure that the the selected fields do generate value. However, in the
combo box, I have only one field that is being displayed instead of two
fields. I would like to know whether this can be solved in the existing code?
Thanks

CODE:
<html>
<head>
<title>Populating two fields in combo box from a query</title>
</head>

<body>
<h2>
Populating two fields in combo box from a query</h2>

<%
Dim oConn
Dim oRS
Dim vCS
Dim sqltxt

set oConn=server.CreateObject("ADODB.connection")
vCS = "Provider=Microsoft.Jet.OLEDB.4.0"
vCS = vCS & "; Data Source=C:\Sailors.mdb"
oConn.connectionstring = vCS
oConn.Open

set oRS = server.CreateObject("ADODB.recordset")
sqltxt = "SELECT BoatName, BoatClass FROM Boats;"
oRS.Open sqltxt,oConn
Response.Write sqltxt & "<br>"
Response.Write oRS("BoatName") & "<br>"
Response.Write oRS("BoatClass") & "<br>"
'Response.End
%>
<select name="lstBoats" size="1">
<%
Do while not oRS.EOF
response.Write "<option value='" & oRS("BoatName") & "'>"
response.Write oRS("BoatClass") & "</option>"
oRS.MoveNext
Loop
%>
</select>
<%oRS.Close
Set oRS = nothing %>

<%'Response.Write "Hey You" & "<br>" %>
</body>
</html>
Jack
8/22/2007 11:18:05 AM
Bob,
Here is the output in html. Thanks
OUTPUT:

<html>
<head>
<title>Populating two fields in combo box from a query</title>
</head>

<body>
<h2>
Populating two fields in combo box from a query</h2>

SELECT BoatName, BoatClass FROM Boats;<br>A Sweet Song<br>Laser<br>
<select name="lstBoats" size="1">
<option value='A Sweet Song'>Laser</option><option
value='Blackbeard'>Laser</option><option value='No Excuse to
Lose'>Laser</option><option value='No Excuse Two Lose'>Laser</option><option
value='White Lightning'>Soling</option><option
value='Teal'>Soling</option><option value='TGV'>Soling</option><option
value='BB3'>Soling</option><option value='Nuts and
Bolts'>Soling</option><option value='Psycho'>Soling</option><option
value='Shasta'>Flying Scot</option><option value='Daphne'>Flying
Scot</option><option value='Red White and Blue'>Flying Scot</option>
</select>

</body>
</html>


[quoted text, click to view]
Jack
8/22/2007 12:14:00 PM
Bob,
In my combo box, I am seeing only one field with the output as
Laser
Laser
Laser
Laser
Soling
Soling
Soling
Soling
Soling
Soling
Flying Scot
Flying Scot
Flying Scot
That's the problem I have. Do you think the size of the combo box needs to
be widened to accommodate the first field or what? Thanks.

[quoted text, click to view]
Jack
8/22/2007 12:38:01 PM
Thanks for the advise Bob. I appreciate it. I will try it. Thanks again.

[quoted text, click to view]
Bob Barrows [MVP]
8/22/2007 1:09:31 PM
[quoted text, click to view]

Please show us the html that results from the code.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Bob Barrows [MVP]
8/22/2007 2:36:09 PM
If the data in Boats looks like this:
A Sweet Song | Laser
Blackbeard | Laser
No Excuse to Lose | Laser
No Excuse Two Lose | Laser
White Lightning | Soling
Teal | Soling
TGV | Soling
BB3 | Soling
Nuts and Bolts | Soling
Psycho | Soling
Shasta | Flying Scot
Daphne | Flying Scot
Red White and Blue | Flying Scot

Then that is the output I would expect from your code

What is wrong with it? What do you want it to look like?

[quoted text, click to view]

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Bob Barrows [MVP]
8/22/2007 3:28:17 PM
No, resizing won't do anything. The combo box (actually, it is called a
"dropdown", or, better yet, a "select" - there is no such combo box in
html) is displaying exactly what the html is telling it to display.

Look at one of the option tags:
<option value='A Sweet Song'>Laser</option>
It sounds as if you are expecting the content of the value attribute ("A
Sweet Song") to be displayed as well as the option tag's text ("Laser" -
the portion between the opening and closing tags). Sorry, it just does
not work that way. The dropdown will display whatever is in the text,
and only what is in the text. So you need to modify your code to make
the resulting html look the way you want it to look, probably via
concatenation. Start with straight html. Write small .htm a page
containing hard-coded html that gives you what you want. Then go back to
your code and modify it so that it results in the same html.


[quoted text, click to view]

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Andyza
9/17/2007 5:14:26 AM
On Aug 22, 9:28 pm, "Bob Barrows [MVP]" <reb01...@NOyahoo.SPAMcom>
[quoted text, click to view]

Something like:

Do while not oRS.EOF
response.Write "<option value='" & oRS("BoatName") & "'>"
response.Write oRS("BoatClass") & " - " & oRS("BoatName") & "</
option>"
oRS.MoveNext
Loop
Evertjan.
9/17/2007 3:09:16 PM
Andyza wrote on 17 sep 2007 in microsoft.public.inetserver.asp.db:

[quoted text, click to view]

I would write that like this:

<%
Do while not oRS.EOF
%>

<option value='<% = oRS("BoatName") %>'>
<% = oRS("BoatClass") %>-<% = oRS("BoatName") %>
</option>

<%
oRS.MoveNext
Loop
%>

Much less error prone for me at least.

[oRS("BoatName") shoud not contain an apostrophe, btw]

--
Evertjan.
The Netherlands.
Adrienne Boswell
9/18/2007 12:00:00 AM
Gazing into my crystal ball I observed "Evertjan."
<exjxw.hannivoort@interxnl.net> writing in news:Xns99AEAE807E270eejj99@
194.109.133.242:

[quoted text, click to view]

Even better for the user:

<select name="field">
<option value="">Select</option>
<% while not ors.EOF %>
<option value="<% = oRS("BoatName") %>" <%if trim(field) = trim(oRS
("BoatName")) then%>selected="selected"<%end if%>><% = oRS("BoatClass")
%>-<% = oRS("BoatName") %></option>
<% ors.movenext
wend
ors.close
set obs = nothing
%>
</select>


--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share
Evertjan.
9/18/2007 12:00:00 AM
Adrienne Boswell wrote on 18 sep 2007 in
microsoft.public.inetserver.asp.db:

[quoted text, click to view]

ors = Oral Rehydration Salts

obs? [oops?] It is nothing. ;-)

More seriously:

I presume that,
if the end of the serverside page code execution is near,
the ASP engine will take care of such closing and nothinging
without any performance damage.

--
Evertjan.
The Netherlands.
AddThis Social Bookmark Button