gridview and arraylist

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
 
J

John Devlon

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
 
M

Matthijs Krempel

Hi John,

Is the name property public?

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

With kind regards,

Matthijs Krempel
 
E

Eliyahu Goldin

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
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top