Good old list boxes.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pauley
    New Member
    • Mar 2008
    • 6

    #1

    Good old list boxes.

    I have an ASP page that has a list box that allows multiple selections. I can take those items selected and submit them to my SQL table. Of course they are submitted as: selection1, selection2, selection3 and so on.

    I can also pull those values back into my list box in an update form by using HTML and ASP code such as:
    Code:
    <option selected value="<% =rs("division") %>"><% =rs("division") %></option>
    However it of course writes them in the top row of the list box and forces the box to be too wide. The list box on the update form has all of the same values as the list box in the submission form.

    How do I make the update form load with the values in the list box selected as they were when the record was first submitted?
  • jeffstl
    Recognized Expert Contributor
    • Feb 2008
    • 432

    #2
    Originally posted by Pauley
    I have an ASP page that has a list box that allows multiple selections. I can take those items selected and submit them to my SQL table. Of course they are submitted as: selection1, selection2, selection3 and so on.

    I can also pull those values back into my list box in an update form by using HTML and ASP code such as:
    Code:
    <option selected value="<% =rs("division") %>"><% =rs("division") %></option>
    However it of course writes them in the top row of the list box and forces the box to be too wide. The list box on the update form has all of the same values as the list box in the submission form.

    How do I make the update form load with the values in the list box selected as they were when the record was first submitted?
    How come you are writing the same database value out twice in a row in this example?
    Code:
    <option selected value="<% =rs("division") %>"><% =rs("division") %></option>
    Two rs("division") in a row will print the same value twice.

    Anyway, if you want to be able to populate the list box the same way you did when you added the record you will have to loop through the values of the listbox and compare each value to the value in your database, then only mark the value that matches with a selected property.

    Code:
    Do While not MyListValuesRS.EOF
         if rs("division") = MyListValuesRS("Value") then
              'here you would write out the option selected
         else
              'here you would write out a non-selected value
         end if
    Wend
    Your post is a little confusing because Im not exactly sure what you mean or what kind of data your working with, or if you have a code to match the list box values, or if you are strictly storing the exact selection they make as a text string. Alot will depend on these things

    Comment

    Working...