gridview and arraylist

  • Thread starter Thread starter John Devlon
  • Start date Start date
J

John Devlon

Hi,

I would like to bind a gridview to an arraylist, which contains a
collection of custom objects.
I've created a gridview, which has a "Name" column and the text field
property set to "Name".

The code I used ....

Dim myList As New ArrayList()

Dim myPerson As clsPerson

myPerson = New clsPerson
myFile.Name = "John"

myList.Add(myFile)

GridView1.DataSource = myList
GridView1.DataBind()

When running the code, an error is trown on the databind line... "there is
no field or property with the name "Name" in the selected source
"

Can anyone please help me ?

John
 
Hi,

I just noticed a small error in the example code...
Dim myList As New ArrayList()

Dim myPerson As clsPerson

myPerson = New clsPerson
myPerson.Name = "John"

myList.Add(myPerson)

GridView1.DataSource = myList
GridView1.DataBind()

Does anyone have an idea ? It's not working...

John
 
Hi John,

Is the name property public?

It's also better to use a generic list, like: List<Person>

With kind regards,

Matthijs Krempel
 
This looks fine. Apparently there is a problem in other parts of the code.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net



Hi,

I just noticed a small error in the example code...
Dim myList As New ArrayList()

Dim myPerson As clsPerson

myPerson = New clsPerson
myPerson.Name = "John"

myList.Add(myPerson)

GridView1.DataSource = myList
GridView1.DataBind()

Does anyone have an idea ? It's not working...

John
 
Back
Top