Rick
asked on
asp.net - selected listbox items into array
Hello,
I have a ListBox control that is being populated in code (from a SQL query).
How do I set the selected items to an ArrayList?
Protected Sub btnGo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGo.Click
Dim arrBrand As ArrayList
For Each item As ListItem In lstBxBrand.Items
If item.Selected = True Then
arrBrand.Add(item.Text)
End If
Next
End Sub
This is giving me a "Object reference not set to an instance of an object", on:
arrBrand.Add(item.Text)
Thank you.
I have a ListBox control that is being populated in code (from a SQL query).
How do I set the selected items to an ArrayList?
Protected Sub btnGo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGo.Click
Dim arrBrand As ArrayList
For Each item As ListItem In lstBxBrand.Items
If item.Selected = True Then
arrBrand.Add(item.Text)
End If
Next
End Sub
This is giving me a "Object reference not set to an instance of an object", on:
arrBrand.Add(item.Text)
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you.
Change the following line:
Dim arrBrand As ArrayList
to
Dim arrBrand As New ArrayList
Dim arrBrand As ArrayList
to
Dim arrBrand As New ArrayList
add this line after the dim statement
arrBrand = new ArrayList