Listbox problem - taking initial value from database

Discussion in 'ASP General' started by Coz, Jul 30, 2003.

  1. Coz

    Coz Guest

    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
    ><%=(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
     
    Coz, Jul 30, 2003
    #1
    1. Advertising

  2. Coz

    Ray at Guest

    <% 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" <> wrote in message
    news:VvFVa.3664$...
    > 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
    > ><%=(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
    >
    >
     
    Ray at, Jul 30, 2003
    #2
    1. Advertising

  3. Coz

    Roy in Guest

    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$...
    > <% 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" <> wrote in message
    > news:VvFVa.3664$...
    > > 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
    > > ><%=(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
    > >
    > >

    >
    >
     
    Roy in, Jul 30, 2003
    #3
  4. Coz

    Ray at Guest

    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 $>" <> wrote in
    message news:%...
    > what the heck is all this:
    >
    > CPEditPropertyRS.Fields.Item("Garage").Value
    >
    > why not just do this
    >
    > CPEditPropertyRS.("Garage")
    >
     
    Ray at, Jul 30, 2003
    #4
  5. Coz

    Coz Guest

    "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    news:%...
    > 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.
     
    Coz, Jul 30, 2003
    #5
  6. Coz

    Ray at Guest

    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" <> wrote in message
    news:BwWVa.4566$...
    > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    > news:%...
    > > 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.
    >
    >
     
    Ray at, Jul 31, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    1,002
  2. Anton
    Replies:
    11
    Views:
    989
    arasu
    Jan 7, 2005
  3. Replies:
    0
    Views:
    497
  4. PGK
    Replies:
    1
    Views:
    522
  5. Jim Cain
    Replies:
    1
    Views:
    209
    Yukihiro Matsumoto
    Jul 18, 2003
Loading...

Share This Page