Link to home
Start Free TrialLog in
Avatar of Rick
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.

ASKER CERTIFIED SOLUTION
Avatar of Vipul Patel
Vipul Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ajb2222
ajb2222

You have declared array brand but havenot set it to an object

add this line after the dim statement

arrBrand = new ArrayList
Avatar of Rick

ASKER

Thank you.
Change the following line:

Dim arrBrand As ArrayList

to

Dim arrBrand As New ArrayList