Return multiple selections in a listbox asp.net 2.0
Hi,
Probably a very simple solution but it is driving me mad.
In asp.net 2.0 vb.net, I have a list box which allows the user to select mulitple selections. These are stored in a database as comma separated values.
When I come to display the result again later, how do I get the multiple selections to be selected?
I extract the data from the database and pop it into an array then loop through that:
FOR
lstBox.SelectedValue = x
Next
But this only puts the last selection of the loop in.
Thanks in anticipation
Andrew
ASP.NET
Last Comment
pashik
8/22/2022 - Mon
pashik
There is hint for u:
look for Property SelectedItems in ListBox.
andrewh123
ASKER
Thanks pashik,
I am trying to set multiple selected values - could you be a bit more specific with your answer as I can't get this to work.
thanks
pashik
Sorry, wrote a bit wrong Property.
Here is hint in C# which u can easliy make in VB.Net
u can try this:
In loop u can set selected items in such way:
listBox1.SetSelected(1,true)
Hi again,
I'm using asp.net - there doesn't appear to be a property setselected for listboxes.
pashik
ok, try this code:
this code used to store values of mselect value in database
Dim ListItemSelected As String
For Each li In ListBoxCoachCategory.Items
If li.Selected = True Then
ListItemSelected = ListItemSelected & li.Value & ","
End If
Next
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
look for Property SelectedItems in ListBox.