Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ASP / Database Access / September 2007



Tip: Looking for answers? Try searching our database.

Still Not Resolved

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jack - 22 Aug 2007 16:40 GMT
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>
Bob Barrows [MVP] - 22 Aug 2007 18:09 GMT
> 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

Please show us the html that results from the code.
Signature

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.

Jack - 22 Aug 2007 19:18 GMT
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>

> > Hi,
> > I want to display two fiels from a query in a combo box. I am
[quoted text clipped - 4 lines]
>
> Please show us the html that results from the code.
Bob Barrows [MVP] - 22 Aug 2007 19:36 GMT
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?

> Bob,
> Here is the output in html. Thanks
[quoted text clipped - 24 lines]
> </body>
> </html>

Signature

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.

Jack - 22 Aug 2007 20:14 GMT
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.

> If the data in Boats looks like this:
> A Sweet Song | Laser
[quoted text clipped - 43 lines]
> > </body>
> > </html>
Bob Barrows [MVP] - 22 Aug 2007 20:28 GMT
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.

> Bob,
> In my combo box, I am seeing only one field with the output as
[quoted text clipped - 69 lines]
>> header is my spam trap, so I don't check it very often. You will get
>> a quicker response by posting to the newsgroup.

Signature

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.

Jack - 22 Aug 2007 20:38 GMT
Thanks for the advise Bob. I appreciate it. I will try it. Thanks again.

> 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
[quoted text clipped - 85 lines]
> >> 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 - 17 Sep 2007 13:14 GMT
On Aug 22, 9:28 pm, "Bob Barrows [MVP]" <reb01...@NOyahoo.SPAMcom>
wrote:

> Look at one of the option tags:
> <option value='A Sweet Song'>Laser</option>
[quoted text clipped - 5 lines]
> the resulting html look the way you want it to look, probably via
> concatenation.

Something like:

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

> Do while not oRS.EOF
>  response.Write "<option value='" & oRS("BoatName") & "'>"
>  response.Write oRS("BoatClass") & " - " & oRS("BoatName") & "</
> option>"
>     oRS.MoveNext
> Loop

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]

Signature

Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Adrienne Boswell - 18 Sep 2007 07:07 GMT
Gazing into my crystal ball I observed "Evertjan."
<exjxw.hannivoort@interxnl.net> writing in news:Xns99AEAE807E270eejj99@
194.109.133.242:

> Andyza wrote on 17 sep 2007 in microsoft.public.inetserver.asp.db:
>
[quoted text clipped - 23 lines]
>
> [oRS("BoatName") shoud not contain an apostrophe, btw]

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>

Signature

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. - 18 Sep 2007 07:53 GMT
Adrienne Boswell wrote on 18 sep 2007 in
microsoft.public.inetserver.asp.db:

> <% ors.movenext
>    wend
>    ors.close
>    set obs = nothing
> %>

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.

Signature

Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.