Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Objects to a ListBox

Status
Not open for further replies.

FederalProgrammer

Programmer
Jul 2, 2003
318
CA
In VB (or C#) .net, it's very easy to add an object to a listbox:
Code:
dim obj as someObject
listbox1.items.add(obj)

I tried the same thing in ASP .NET (No luck!)
So, now I've "bounded" my ListBox to an arraylist of Objects. The way it works is as follows: User interacts with the system to create the object. Then user clicks on "Add to List" button at which point the new object should be added to the listbox;

My problem is that, as the user clicks on "Add to list" button, the size of the arraylist doesn't change (it is always equal to 1 and the arraylist contains the most recent object)
Somehow, the arraylist gets re-initialized, everytime my user clicks on the "Add to List" button! (I have even tried to store this arraylist as a session variable... still the arraylist contains only 1 item!!)

Any ideas?



---------------
 
Here are the two funx involved in adding the object to my listbox:

Code:
Private Sub Page_Load(ByVal s As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'If (Not Me.IsPostBack) Then
        Me._list = New ArrayList
        Me.ListBox1.DataSource = Me._list
        Me.ListBox1.DataBind()
        'End If

    End Sub

Code:
Private Sub btnAddBandMember_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddBandMember.Click
        Dim newObject As New SomeObject()
        Me._list.Add(newObject)
        Me.ListBox1.DataBind()

    End Sub

My problem is that me._list always contains a single object!!! what's going on with this thing?



---------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top