Listbox problem - taking initial value from database

C

Coz

Hi all,

I'm looking for help again!!! I have been writing a page to update a
database but now have another 'silly' problem with listbox's...Grrr...

I'm trying to populate the list box with static values pre-programmed into
the page and then set the listbox value to that of the one contained in the
database for that particular record the code I'm using is -

<select name="SelectGarage">
<option value="0">No</option>
<option value="1">Yes</option>
<option value="2">Yes (Two)</option>
<%=(CPEditPropertyRS.Fields.Item("Garage").Value)%></option>
</select>

The listbox comes up OK and the value contained in the database is
displayed, but if the number '1' (for Yes) is the value stored in the record
to be edited, the value is displayed as a '1' and not a 'yes'. I don't want
it to actually add the value in the record, I want it to select the
corresponding label i.e. '1' = 'Yes'.

Can anyone help........

Cheers
Coz
 
R

Ray at

<% TheCurrentValueFromTheDB = CPEditPropertyRS.Fields.Item("Garage").Value
%>

<select name="SelectGarage">
<option value="0"<% If TheCurrentValueFromTheDB = "0" Then
Response.Write " selected"%>>No</option>
<option value="1"<% If TheCurrentValueFromTheDB = "1" Then
Response.Write " selected"%>>Yes</option>
<option value="2"<% If TheCurrentValueFromTheDB = "2" Then
Response.Write " selected"%>>Yes (Two)</option>
<option value="3"<% If TheCurrentValueFromTheDB = "3" Then
Response.Write " selected"%>>Double</option>
</select>

Ray at home
 
R

Roy in

what the heck is all this:

CPEditPropertyRS.Fields.Item("Garage").Value

why not just do this

CPEditPropertyRS.("Garage")
 
R

Ray at

Fully qualifying is a good practice, especially if you plan on moving to
..net.

Ray at home
 
C

Coz

Ray at said:
Fully qualifying is a good practice, especially if you plan on moving to
.net.

Ray at home
<SNIP

Cheers guy's,
I have just tried the code and it works a treat:)
I have used the long method to do it mainly to try and drum it into myself
what its doing.
On the comment that Ray (the one at home) made about moving to .net - (OK I
know this will sound stupid) but should I? What will it do for me that the
current stuff will not?

Thanks again

Coz.
 
R

Ray at

You should move to it if for no other reason just to keep your marketability
up to date, imo. Think about if all you knew was fortran or some other
antiquated language, not that classic ASP is antiquated. (No, I did not
just call ASP a language!)

Ray at home
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top