Arraylist only display last item

Discussion in 'ASP .Net' started by David Lozzi, Feb 13, 2006.

  1. David Lozzi

    David Lozzi Guest

    Hello,

    I have an arraylist that loads a checkboxlist. I populate the arraylist
    using a custom class and pulling the data from the web.config file. When the
    checkboxlist is loaded, only the last item in the list is displayed for each
    item, in other words, item #4 is displayed 4 times. My code is below.

    Thanks


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    If Not IsPostBack Then
    LoadHire()
    End If
    End Sub

    Sub LoadHire()
    Dim opts() As String =
    ConfigurationSettings.AppSettings("HireSelection").Split(";")
    Dim chks As New ArrayList

    For i As Integer = 0 To opts.Length - 1
    Dim opt As New NewHire(opts(i), opts(i))
    chks.Add(opt)
    Next

    chkForHire.DataSource = chks
    chkForHire.DataBind()
    End Sub




    Public Class NewHire
    Private Shared _val As String = [String].Empty
    Private Shared _text As String = [String].Empty

    Public Property DataValue1() As String
    Get
    Return _val
    End Get
    Set(ByVal Value As String)
    _val = Value
    End Set
    End Property

    Public Property DataText1() As String
    Get
    Return _text
    End Get
    Set(ByVal Value As String)
    _text = Value
    End Set
    End Property

    Public Sub New(ByVal val As String, ByVal txt As String)
    Me._val = val
    Me._text = txt
    End Sub
    End Class

    --
    David Lozzi
    Web Applications Developer
    dlozzi@(remove-this)delphi-ts.com
    David Lozzi, Feb 13, 2006
    #1
    1. Advertising

  2. ur field values are shared, they shoudln't be.

    Karl

    --
    http://www.openmymind.net/
    http://www.fuelindustries.com/


    "David Lozzi" <> wrote in message
    news:%...
    > Hello,
    >
    > I have an arraylist that loads a checkboxlist. I populate the arraylist
    > using a custom class and pulling the data from the web.config file. When
    > the checkboxlist is loaded, only the last item in the list is displayed
    > for each item, in other words, item #4 is displayed 4 times. My code is
    > below.
    >
    > Thanks
    >
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > If Not IsPostBack Then
    > LoadHire()
    > End If
    > End Sub
    >
    > Sub LoadHire()
    > Dim opts() As String =
    > ConfigurationSettings.AppSettings("HireSelection").Split(";")
    > Dim chks As New ArrayList
    >
    > For i As Integer = 0 To opts.Length - 1
    > Dim opt As New NewHire(opts(i), opts(i))
    > chks.Add(opt)
    > Next
    >
    > chkForHire.DataSource = chks
    > chkForHire.DataBind()
    > End Sub
    >
    >
    >
    >
    > Public Class NewHire
    > Private Shared _val As String = [String].Empty
    > Private Shared _text As String = [String].Empty
    >
    > Public Property DataValue1() As String
    > Get
    > Return _val
    > End Get
    > Set(ByVal Value As String)
    > _val = Value
    > End Set
    > End Property
    >
    > Public Property DataText1() As String
    > Get
    > Return _text
    > End Get
    > Set(ByVal Value As String)
    > _text = Value
    > End Set
    > End Property
    >
    > Public Sub New(ByVal val As String, ByVal txt As String)
    > Me._val = val
    > Me._text = txt
    > End Sub
    > End Class
    >
    > --
    > David Lozzi
    > Web Applications Developer
    > dlozzi@(remove-this)delphi-ts.com
    >
    >
    >
    >
    Karl Seguin [MVP], Feb 13, 2006
    #2
    1. Advertising

  3. David Lozzi

    David Lozzi Guest

    DUH! Thank you!!

    --
    David Lozzi
    Web Applications Developer
    dlozzi@(remove-this)delphi-ts.com



    "Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
    net> wrote in message news:%23tk$...
    > ur field values are shared, they shoudln't be.
    >
    > Karl
    >
    > --
    > http://www.openmymind.net/
    > http://www.fuelindustries.com/
    >
    >
    > "David Lozzi" <> wrote in message
    > news:%...
    >> Hello,
    >>
    >> I have an arraylist that loads a checkboxlist. I populate the arraylist
    >> using a custom class and pulling the data from the web.config file. When
    >> the checkboxlist is loaded, only the last item in the list is displayed
    >> for each item, in other words, item #4 is displayed 4 times. My code is
    >> below.
    >>
    >> Thanks
    >>
    >>
    >> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    >> System.EventArgs) Handles MyBase.Load
    >> If Not IsPostBack Then
    >> LoadHire()
    >> End If
    >> End Sub
    >>
    >> Sub LoadHire()
    >> Dim opts() As String =
    >> ConfigurationSettings.AppSettings("HireSelection").Split(";")
    >> Dim chks As New ArrayList
    >>
    >> For i As Integer = 0 To opts.Length - 1
    >> Dim opt As New NewHire(opts(i), opts(i))
    >> chks.Add(opt)
    >> Next
    >>
    >> chkForHire.DataSource = chks
    >> chkForHire.DataBind()
    >> End Sub
    >>
    >>
    >>
    >>
    >> Public Class NewHire
    >> Private Shared _val As String = [String].Empty
    >> Private Shared _text As String = [String].Empty
    >>
    >> Public Property DataValue1() As String
    >> Get
    >> Return _val
    >> End Get
    >> Set(ByVal Value As String)
    >> _val = Value
    >> End Set
    >> End Property
    >>
    >> Public Property DataText1() As String
    >> Get
    >> Return _text
    >> End Get
    >> Set(ByVal Value As String)
    >> _text = Value
    >> End Set
    >> End Property
    >>
    >> Public Sub New(ByVal val As String, ByVal txt As String)
    >> Me._val = val
    >> Me._text = txt
    >> End Sub
    >> End Class
    >>
    >> --
    >> David Lozzi
    >> Web Applications Developer
    >> dlozzi@(remove-this)delphi-ts.com
    >>
    >>
    >>
    >>

    >
    >
    David Lozzi, Feb 13, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Saravanan Rathinavelu

    Iterate through ArrayList using an another ArrayList

    Saravanan Rathinavelu, Aug 16, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    2,738
    Natty Gur
    Aug 19, 2003
  2. Kaidi
    Replies:
    4
    Views:
    2,370
    Kaidi
    Jan 3, 2004
  3. sangram
    Replies:
    16
    Views:
    1,983
  4. Johny
    Replies:
    8
    Views:
    390
  5. BenM
    Replies:
    2
    Views:
    311
    Morris
    Feb 1, 2005
Loading...

Share This Page