Link to home
Create AccountLog in
Avatar of andrewh123
andrewh123

asked on

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
Avatar of pashik
pashik

There is hint for u:
look for Property SelectedItems in ListBox.
Avatar of 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
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.
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

Next
ASKER CERTIFIED SOLUTION
Avatar of pashik
pashik

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account