multiselect listbox - set selections using delimeted string
-
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
-
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
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.
-
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.
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