Arraylist only display last item

D

David Lozzi

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
 
D

David Lozzi

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:%[email protected]...
ur field values are shared, they shoudln't be.

Karl

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


David Lozzi said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top