Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. multiselect listbox - set selections using delimeted string

multiselect listbox - set selections using delimeted string

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-netdatabasedata-structures
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    ublend
    wrote on last edited by
    #1

    I have a multiselect listbox that sends selections to the database field separated by commas - no problem there. No problem displaying the data. I need to allow folks to edit the form data so I have a formview with all fields bound but when I try to bind the multiselect listbox, I get an error (because the data does not match the listbox items) - So, I put the data into an array, intending to use the array values to set the selected items in the listbox. But I am a long time asp coder and cannot get my brain around how to do this with asp.net (VB)... I'm sure that I need to loop through the array values and compare them to the listbox values (loop within loop...) I cannot believe I am the only one out there who has had to set the selections of a listbox this way... Any help is MOST appreciated. This rediculous issue is holding up my entire project..... Thanks

    ublend

    W 1 Reply Last reply
    0
    • U ublend

      I have a multiselect listbox that sends selections to the database field separated by commas - no problem there. No problem displaying the data. I need to allow folks to edit the form data so I have a formview with all fields bound but when I try to bind the multiselect listbox, I get an error (because the data does not match the listbox items) - So, I put the data into an array, intending to use the array values to set the selected items in the listbox. But I am a long time asp coder and cannot get my brain around how to do this with asp.net (VB)... I'm sure that I need to loop through the array values and compare them to the listbox values (loop within loop...) I cannot believe I am the only one out there who has had to set the selections of a listbox this way... Any help is MOST appreciated. This rediculous issue is holding up my entire project..... Thanks

      ublend

      W Offline
      W Offline
      www Developerof NET
      wrote on last edited by
      #2

      Just to get you started i would give you the logic to be implemented. You need a nested for loop, the outer loop spanning the length equal to the master data size while the inner loop spanning the length of the array obtained by splitting up the delimited values. Later you just need to check the value of the outer loop and the inner loop and if the match is found, mark the outer loop item as selected. Hope this helps.

      When you fail to plan, you are planning to fail.

      U 1 Reply Last reply
      0
      • W www Developerof NET

        Just to get you started i would give you the logic to be implemented. You need a nested for loop, the outer loop spanning the length equal to the master data size while the inner loop spanning the length of the array obtained by splitting up the delimited values. Later you just need to check the value of the outer loop and the inner loop and if the match is found, mark the outer loop item as selected. Hope this helps.

        When you fail to plan, you are planning to fail.

        U Offline
        U Offline
        ublend
        wrote on last edited by
        #3

        thanks for the reply - I found that I was making it way too complicated... :laugh: Condango had the solution: to highlight from database to multiselect where SelectedDisplayValue is the value from database(eg SelectedDisplayValue= 3,4,10) For i = 0 To (objListbox.Items.Count - 1) If InStr(SelectedDisplayValue, objListbox.Items(i).Value) Then objListbox.Items(i).Selected = True End If Next

        ublend

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups