Database update using multiselect listbox

A common scenario that developers may encounter is to associate many database
records with a record from another table. The example that I’ll use is to
associate a number of facilities with a particular property. On a webpage,
the user can insert a property into the database. The page will also have
a multiselect listbox for the user to associate many facilities with that
property. The facilities are then stored as a comma delimited string in the
Properties table.

The main problem that developers have is updating the property record. On
the update page, the associated facilities in the listbox should be pre-selected.
It’s not immediately obvious on how to do this. You can download the support
files by clicking the link at the bottom of this article. The important code
is for the listbox on the edit.asp page

 <select name="Facilities" size="5" multiple id="Facilities">
                    <%
While (NOT FacilitiesRS.EOF)
%>
<%
Facilities=ListingsRS("Facilities") & ""
IsSelected=false
'Put the comma separated facilities into an Array
Arr=Split(Facilities,",")
for i=0 to ubound(Arr)
if trim(Arr(i))=FacilitiesRS("Facility") then
IsSelected=true
Exit for
end if
next
%>
  <option <%if IsSelected then Response.Write "selected"%> 
  value="<%=(FacilitiesRS.Fields.Item("Facility").Value)%>">
  <%=(FacilitiesRS.Fields.Item("Facility").Value)%>
  </option>
                    <%
  FacilitiesRS.MoveNext()
Wend
If (FacilitiesRS.CursorType > 0) Then
  FacilitiesRS.MoveFirst
Else
  FacilitiesRS.Requery
End If
%>
                </select>
 

Note how the original value is split into an array. The code then loops through
the arrayt to compare it to the value in the listbox. If there is a match,
we can set the option to be selected.

Also, note that this is a quick’n’dirty solution. Technically, one should
use a separate table to store the relationships. 

Updated: March 6, 2015 — 5:15 pm

Comments

Add a Comment
  1. Your comment is awaiting moderation.

    You actually mentioned it effectively.
    https://www.waltcoexpress.com/
    mexican pharmacy online
    canadian pharmacies
    best canadian mail order pharmacies
    canadian pharmacies

  2. Your comment is awaiting moderation.

    Incredible a lot of beneficial tips!
    https://www.dunamisproductions.com/
    online pharmacy without a prescription
    canadian cialis
    canadian pharmacy reviews
    mexican pharmacies shipping to usa

  3. Your comment is awaiting moderation.

    You said it perfectly.!
    https://www.lunarciel.com/
    canadian pharmacy without prescription
    online pharmacies of canada
    online prescription drugs
    canadian pharmacy online

  4. Your comment is awaiting moderation.

    Appreciate it! A good amount of advice.

    https://www.dunamisproductions.com/
    online pharmacy reviews
    canadian drugs
    pharmacy online mexico
    canada pharmaceuticals online

  5. Your comment is awaiting moderation.

    Awesome information. Thank you!
    https://www.waltcoexpress.com/
    northwest pharmacy canada
    canadian pharmacy online
    cheap prescription drugs online
    canada pharmacy

  6. Your comment is awaiting moderation.

    Good information. Thanks a lot!
    https://www.interlandchemie.com/
    discount drugs online pharmacy
    canada pharmaceuticals online
    prescription drugs without prior prescription
    northwestpharmacy

  7. Your comment is awaiting moderation.

    Regards. I like this.
    https://www.waltcoexpress.com/
    canadapharmacyonline.com
    canadian pharmacies that ship to us
    best price prescription drugs
    north west pharmacy canada

  8. Your comment is awaiting moderation.

    Kudos! I value it.
    https://www.waltcoexpress.com/
    legitimate canadian mail order pharmacies
    canada drugs
    discount pharmacy online
    canadian drugs

  9. Your comment is awaiting moderation.

    Nicely put, Regards.
    https://www.dunamisproductions.com/
    canada drugs
    canadianpharmacy
    canadian pharmacy online canada
    canadian pharmacies without an rx

  10. Your comment is awaiting moderation.

    Cheers, I value it.
    https://www.waltcoexpress.com/
    pharmacy without dr prescriptions
    canadian pharmacies that ship to us
    canadian pharmacies that ship to us
    canadianpharmacy

  11. Your comment is awaiting moderation.

    Terrific content. Thanks a lot.
    https://www.dunamisproductions.com/
    reputable canadian mail order pharmacies
    aarp approved canadian online pharmacies
    canadian pharmacies without prescriptions
    canadian pharmacy

  12. Your comment is awaiting moderation.

    Thanks! I appreciate it!
    https://www.dunamisproductions.com/
    drug costs
    canada drugs online
    canadian drugstore online
    canada pharmaceuticals online

  13. Your comment is awaiting moderation.

    Position very well regarded.!
    https://www.interlandchemie.com/
    cialis online
    top rated canadian pharmacies online
    canadian pharmacy online canada
    canadian online pharmacies

  14. Your comment is awaiting moderation.

    You said this terrifically.
    https://www.waltcoexpress.com/
    canada pharmacies online pharmacy
    canadian online pharmacy
    online pharmacy no prescription needed
    london drugs canada

  15. Your comment is awaiting moderation.

    Kudos. I appreciate this.
    https://www.interlandchemie.com/
    canadianpharmacy
    canadian pharmacies without an rx
    trusted overseas pharmacies
    canadian pharmacies

  16. Your comment is awaiting moderation.

    Info well regarded!!
    https://www.lunarciel.com/
    best online pharmacy stores
    mexican pharmacies shipping to usa
    buy prescription drugs online
    canada drugs

  17. Your comment is awaiting moderation.

    Well voiced genuinely! .
    https://www.waltcoexpress.com/
    medication costs
    north west pharmacy canada
    safe canadian online pharmacies
    canadian viagra

  18. Your comment is awaiting moderation.

    Perfectly expressed without a doubt. .
    https://www.waltcoexpress.com/
    canadian pharmacies online
    canadianpharmacy
    prescription drugs prices
    canadianpharmacy

  19. Your comment is awaiting moderation.

    You made your position extremely clearly.!
    https://www.dunamisproductions.com/
    canada pharmacies prescription drugs
    canadian cialis
    canadian pharmacies that are legit
    canadian online pharmacies

  20. Your comment is awaiting moderation.

    Regards. Wonderful information!
    https://www.lunarciel.com/
    pharmacy prescription
    canada pharmacy
    safe canadian online pharmacies
    canadian pharmacies without an rx

  21. Your comment is awaiting moderation.

    You explained that adequately.
    https://www.waltcoexpress.com/
    drug prices comparison
    mexican pharmacies shipping to usa
    canadian pharmacy meds
    canadian pharmacies

  22. Your comment is awaiting moderation.

    Nicely put, Kudos.
    https://www.lunarciel.com/
    pharmacy drug store
    online pharmacies canada
    canadian pharmacies online
    trust pharmacy canada

  23. Your comment is awaiting moderation.

    Truly tons of great info.
    https://www.visitwaushara.com/
    best canadian pharmacies
    mexican pharmacies shipping to usa
    canada drug prices
    canadian pharcharmy

  24. Your comment is awaiting moderation.

    Wonderful facts. Thanks!
    https://www.visitwaushara.com/
    buying drugs canada
    canadian pharmacy
    candrugstore com
    canadian drugs

  25. Your comment is awaiting moderation.

    Fantastic write ups. Appreciate it.
    https://www.interlandchemie.com/
    visit poster’s website
    canadian pharmacies online
    prescription cost comparison
    canadian pharmacy

  26. Your comment is awaiting moderation.

    Truly a lot of great knowledge.
    https://www.waltcoexpress.com/
    canadian pharmacy uk delivery
    london drugs canada
    canada pharmacy online reviews
    canada pharmaceuticals online

  27. Your comment is awaiting moderation.

    You stated it fantastically!
    https://www.dunamisproductions.com/
    online drugs
    london drugs canada
    best canadian pharmacies
    canadian pharmacies that ship to us

  28. Your comment is awaiting moderation.

    You expressed this fantastically!
    https://www.dunamisproductions.com/
    prescription drugs online without doctor
    london drugs canada
    no prescription online pharmacy
    canadian pharmacy

  29. Your comment is awaiting moderation.

    Superb advice. Cheers!
    https://www.interlandchemie.com/
    canadianpharmacy
    canada drugs online
    global pharmacy canada
    canada pharmacy online

  30. Your comment is awaiting moderation.

    You actually revealed it well.
    https://www.waltcoexpress.com/
    pharmacy tech
    canada drugs online
    online pharmacy without a prescription
    canadian viagra

  31. Your comment is awaiting moderation.

    Wow quite a lot of superb advice!
    https://www.dunamisproductions.com/
    best canadian pharmacies
    north west pharmacy canada
    walgreens pharmacy
    canada drugs online

  32. Your comment is awaiting moderation.

    You’ve made your stand quite nicely.!
    https://www.interlandchemie.com/
    mail order pharmacies
    canadian online pharmacy
    northwest pharmacy canada
    canada pharmaceutical online ordering

  33. Your comment is awaiting moderation.

    This is nicely put. !
    https://www.lunarciel.com/
    medical information online
    northwestpharmacy
    trust pharmacy canada
    northwest pharmacy

  34. Your comment is awaiting moderation.

    Cheers, I enjoy it!
    https://www.waltcoexpress.com/
    canadian pharmacy king
    canadian cialis
    prescription drugs without prior prescription
    canada pharmaceuticals online

  35. Your comment is awaiting moderation.

    Incredible all kinds of awesome advice!
    https://www.waltcoexpress.com/
    web medical information
    canadian pharmacy
    online pharmacies no prescription
    aarp approved canadian online pharmacies

  36. Your comment is awaiting moderation.

    Valuable material. Thanks!
    https://www.interlandchemie.com/
    canadian pharmacies that are legit
    canada pharmacy online
    no prescription pharmacy
    canadian viagra

  37. Your comment is awaiting moderation.

    This is nicely expressed! .
    https://www.dunamisproductions.com/
    24 hour pharmacy
    online pharmacies canada
    price prescription drugs
    canadian pharmacies without an rx

  38. Your comment is awaiting moderation.

    Nicely put, Thanks a lot!
    https://www.interlandchemie.com/
    canadian pharmacy king
    canada online pharmacies
    canadian rx pharmacy online
    canadian pharmacies

  39. Your comment is awaiting moderation.

    Superb info. Thank you!
    https://www.interlandchemie.com/
    international pharmacy
    canada drug
    discount drugs online pharmacy
    canadian pharmacies

  40. Your comment is awaiting moderation.

    This is nicely said. !
    https://www.waltcoexpress.com/
    online pharmacy usa
    canada pharmaceuticals online
    rx price comparison
    trust pharmacy canada

  41. Your comment is awaiting moderation.

    Perfectly voiced really! .
    https://www.lunarciel.com/
    pain meds online without doctor prescription
    canada pharmaceutical online ordering
    compare rx prices
    canadianpharmacy

  42. Your comment is awaiting moderation.

    Cheers. Quite a lot of material!

    https://www.visitwaushara.com/
    canadian pharmacy king
    canadian pharmaceuticals online
    canadian pharmacy viagra brand
    canadian cialis

  43. Your comment is awaiting moderation.

    Good forum posts. Thanks.
    https://www.interlandchemie.com/
    highest rated canadian pharmacies
    canada pharmacy online
    best online canadian pharcharmy
    canadian pharmacy

  44. Your comment is awaiting moderation.

    Wow lots of great data!
    https://www.waltcoexpress.com/
    online pharmacy without a prescription
    north west pharmacy canada
    online canadian pharmacies
    canadian pharmacies that ship to us

  45. Your comment is awaiting moderation.

    You reported it perfectly!
    https://www.interlandchemie.com/
    highest rated canadian pharmacies
    canada online pharmacies
    prescription drugs prices
    canada pharmaceuticals online

  46. Your comment is awaiting moderation.

    Kudos, Great information.
    https://www.lunarciel.com/
    legitimate online pharmacies
    canadian pharcharmy
    pharmacy canada
    canadian pharmacies that ship to us

  47. Your comment is awaiting moderation.

    Reliable forum posts. Cheers.
    https://www.visitwaushara.com/
    pharmacy price comparison
    trust pharmacy canada
    pharmacy tech
    canadian pharmacies that ship to us

  48. Your comment is awaiting moderation.

    Terrific forum posts. With thanks!
    https://www.interlandchemie.com/
    reputable canadian mail order pharmacies
    canadian pharmacy
    trusted overseas pharmacies
    canadian pharmacies online

  49. Your comment is awaiting moderation.

    Info clearly considered!.
    https://www.waltcoexpress.com/
    online pharmacy canada
    canadian pharmacies-24h
    canada drugs pharmacy
    canada drug

  50. Your comment is awaiting moderation.

    Fantastic write ups. Many thanks!
    https://www.waltcoexpress.com/
    canada pharmacy online reviews
    canadian pharmacies that ship to us
    canadapharmacy com
    canada pharmacy online

  51. Your comment is awaiting moderation.

    You suggested that very well!
    https://www.visitwaushara.com/
    canadian prescription drugs
    canadian pharmaceuticals online
    canadian drugstore
    canadianpharmacy

  52. Your comment is awaiting moderation.

    Wow a lot of helpful advice.
    https://www.dunamisproductions.com/
    drugs from canada
    canada drugs
    no prescription pharmacy
    trust pharmacy canada

  53. Your comment is awaiting moderation.

    Wonderful stuff. Kudos!
    https://www.interlandchemie.com/
    no 1 canadian pharcharmy online
    canadian pharmacies without an rx
    canadian pharmacies that ship to us
    canada online pharmacies

  54. Your comment is awaiting moderation.

    Many thanks. Great stuff.
    https://www.lunarciel.com/
    onlinecanadianpharmacy.com
    northwest pharmacy
    canada pharmacies without script
    canadian pharmacy online

  55. Your comment is awaiting moderation.

    Excellent material. Thank you.
    https://www.lunarciel.com/
    buy drugs online
    northwest pharmacy
    prescription drug cost
    mexican pharmacies shipping to usa

  56. Your comment is awaiting moderation.

    Superb information. With thanks!
    https://www.visitwaushara.com/
    costco pharmacy pricing
    canada pharmaceutical online ordering
    canadian pharmacies online prescriptions
    canadian cialis

  57. Your comment is awaiting moderation.

    You explained this very well!
    https://www.interlandchemie.com/
    the canadian pharmacy
    canadianpharmacy
    top rated online canadian pharmacies
    canadian pharmacies that ship to us

  58. Your comment is awaiting moderation.

    Thank you. Numerous knowledge!

    https://www.visitwaushara.com/
    medication costs
    canadian pharmacy online
    best online canadian pharcharmy
    north west pharmacy canada

  59. Your comment is awaiting moderation.

    Many thanks! I like it.
    https://www.dunamisproductions.com/
    canada pharmacies
    canada drug
    top rated canadian pharmacies online
    canada online pharmacies

  60. Your comment is awaiting moderation.

    You suggested this effectively.
    https://www.dunamisproductions.com/
    mexican pharmacies
    canada online pharmacies
    canadian pharma companies
    canada online pharmacies

  61. Your comment is awaiting moderation.

    You definitely made the point!
    https://www.waltcoexpress.com/
    online canadian discount pharmacy
    canadianpharmacy
    prescription price comparison
    trust pharmacy canada

  62. Your comment is awaiting moderation.

    Awesome stuff. Thanks!
    https://www.visitwaushara.com/
    mail order pharmacy
    canada pharmaceuticals online
    canadian pharmacy online canada
    canadian pharmacies online

  63. Your comment is awaiting moderation.

    You actually mentioned that adequately!
    https://www.waltcoexpress.com/
    canadian drugstore reviews
    canadian pharmaceuticals online
    canada pharmacy no prescription
    canada drugs

  64. Your comment is awaiting moderation.

    Thanks a lot! Numerous information!

    https://www.dunamisproductions.com/
    most reliable canadian pharmacies
    canada drug
    compare prescription prices
    canada pharmacy

  65. Your comment is awaiting moderation.

    You expressed it exceptionally well.
    http://canadianpharmaciescubarx.com/
    canada pharmacies
    canadian cialis
    northwest pharmacy
    london drugs canada

  66. Your comment is awaiting moderation.

    Information nicely considered..
    https://nicktambone.com/
    canadian online pharmacy
    canadian pharmacies
    cialis canadian pharmacy
    canadian pharmacy online

  67. Your comment is awaiting moderation.

    Regards. An abundance of advice!

    http://canadianonlinepharmacynnm.com/
    online drugstore
    canadian pharmacies online
    canadian family pharmacy
    canadian pharmacies that ship to us

  68. Your comment is awaiting moderation.

    Whoa a good deal of very good information.
    http://canadianpharmacysilo.com/
    approved canadian pharmacies online
    canada drug
    prescription drug assistance
    canada pharmaceutical online ordering

  69. Your comment is awaiting moderation.

    Thank you. I like this.
    http://canadianpharmacysilo.com/
    legitimate canadian mail order pharmacies
    north west pharmacy canada
    canadian pharmacies online
    canada pharmacy online

  70. Your comment is awaiting moderation.

    Well expressed indeed. .
    http://www.canadianpharmacymsn.com/
    buy prescription drugs without doctor
    canada pharmacy
    online rx pharmacy
    canadian pharmacies that ship to us

  71. Your comment is awaiting moderation.

    Amazing loads of excellent facts.
    http://canadianpharmacyntx.com/
    discount prescription drug
    canadian pharmacies-24h
    canadapharmacy com
    trust pharmacy canada

  72. Your comment is awaiting moderation.

    Lovely posts, Appreciate it.
    http://canadianpharmacymim.com/
    compare prescription prices
    canada pharmacy online
    pain meds online without doctor prescription
    canadian pharmacies without an rx

  73. Your comment is awaiting moderation.

    You actually reported that perfectly!
    http://talahicc.com/
    cheap prescription drugs online
    canadian online pharmacy
    mexican pharmacies
    canadian pharmacies online

Leave a Reply

Your email address will not be published. Required fields are marked *