Connecting Tech Pros Worldwide Forums | Help | Site Map

Listbox problem - taking initial value from database

Coz
Guest
 
Posts: n/a
#1: Jul 19 '05
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>
<option value="3">Double</option>
<option value selected[color=blue]
><%=(CPEditPropertyRS.Fields.Item("Garage").Value) %></option>[/color]
</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



Ray at
Guest
 
Posts: n/a
#2: Jul 19 '05

re: Listbox problem - taking initial value from database


<% 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

--
Will trade ASP help for SQL Server help


"Coz" <nospammers@please.com> wrote in message
news:VvFVa.3664$bG5.34209960@news-text.cableinet.net...[color=blue]
> 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[/color]
the[color=blue]
> 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>
> <option value="3">Double</option>
> <option value selected[color=green]
> ><%=(CPEditPropertyRS.Fields.Item("Garage").Value) %></option>[/color]
> </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[/color]
record[color=blue]
> to be edited, the value is displayed as a '1' and not a 'yes'. I don't[/color]
want[color=blue]
> 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
>
>[/color]


Roy in
Guest
 
Posts: n/a
#3: Jul 19 '05

re: Listbox problem - taking initial value from database


what the heck is all this:

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

why not just do this

CPEditPropertyRS.("Garage")

"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:eeS8Y$jVDHA.2236@TK2MSFTNGP12.phx.gbl...[color=blue]
> <% TheCurrentValueFromTheDB = CPEditPropertyRS.Fields.Item("Garage").Value
> %>
>
> <select name="SelectGarage">
> <option value="0"<% If TheCurrentValueFromTheDB = "0"[/color]
Then[color=blue]
> Response.Write " selected"%>>No</option>
> <option value="1"<% If TheCurrentValueFromTheDB = "1"[/color]
Then[color=blue]
> Response.Write " selected"%>>Yes</option>
> <option value="2"<% If TheCurrentValueFromTheDB = "2"[/color]
Then[color=blue]
> Response.Write " selected"%>>Yes (Two)</option>
> <option value="3"<% If TheCurrentValueFromTheDB = "3"[/color]
Then[color=blue]
> Response.Write " selected"%>>Double</option>
> </select>
>
> Ray at home
>
> --
> Will trade ASP help for SQL Server help
>
>
> "Coz" <nospammers@please.com> wrote in message
> news:VvFVa.3664$bG5.34209960@news-text.cableinet.net...[color=green]
> > 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[/color][/color]
into[color=blue][color=green]
> > the page and then set the listbox value to that of the one contained in[/color]
> the[color=green]
> > 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>
> > <option value="3">Double</option>
> > <option value selected[color=darkred]
> > ><%=(CPEditPropertyRS.Fields.Item("Garage").Value) %></option>[/color]
> > </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[/color]
> record[color=green]
> > to be edited, the value is displayed as a '1' and not a 'yes'. I don't[/color]
> want[color=green]
> > 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
> >
> >[/color]
>
>[/color]


Ray at
Guest
 
Posts: n/a
#4: Jul 19 '05

re: Listbox problem - taking initial value from database


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

Ray at home

--
Will trade ASP help for SQL Server help


"Roy in <%=H.E.Double Toothpicks $>" <Roy@DoubleToothpicks.com> wrote in
message news:%23ezNAhlVDHA.2260@TK2MSFTNGP09.phx.gbl...[color=blue]
> what the heck is all this:
>
> CPEditPropertyRS.Fields.Item("Garage").Value
>
> why not just do this
>
> CPEditPropertyRS.("Garage")
>[/color]


Coz
Guest
 
Posts: n/a
#5: Jul 19 '05

re: Listbox problem - taking initial value from database


"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:%23sg1hzoVDHA.2316@TK2MSFTNGP09.phx.gbl...[color=blue]
> Fully qualifying is a good practice, especially if you plan on moving to
> .net.
>
> Ray at home
>[/color]
<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.


Ray at
Guest
 
Posts: n/a
#6: Jul 19 '05

re: Listbox problem - taking initial value from database


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

--
Will trade ASP help for SQL Server help


"Coz" <nospammers@please.com> wrote in message
news:BwWVa.4566$176.41573625@news-text.cableinet.net...[color=blue]
> "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
> news:%23sg1hzoVDHA.2316@TK2MSFTNGP09.phx.gbl...[color=green]
> > Fully qualifying is a good practice, especially if you plan on moving to
> > .net.
> >
> > Ray at home
> >[/color]
> <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[/color]
I[color=blue]
> know this will sound stupid) but should I? What will it do for me that the
> current stuff will not?
>
> Thanks again
>
> Coz.
>
>[/color]


Closed Thread