gridview and arraylist

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 =3D New clsPerson
myFile.Name =3D "John"

myList.Add(myFile)

GridView1.DataSource =3D 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
John Devlon [ Mi, 09 April 2008 16:49 ] [ ID #1938638 ]

Re: gridview and arraylist

Hi,

I just noticed a small error in the example code...

> Dim myList As New ArrayList()
>
> Dim myPerson As clsPerson
>
> myPerson =3D New clsPerson
> myPerson.Name =3D "John"
>
> myList.Add(myPerson)
>
> GridView1.DataSource =3D myList
> GridView1.DataBind()

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

John
John Devlon [ Mi, 09 April 2008 16:52 ] [ ID #1938639 ]

Re: gridview and arraylist

Hi John,

Is the name property public?

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

With kind regards,

Matthijs Krempel

"John Devlon" <johndevlon [at] hotmail.com> schreef in bericht
news:op.t9cl9nv895o8pp [at] laptoptim.wag325n...
>
> 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
>
>
>
Matthijs Krempel [ Mi, 09 April 2008 17:07 ] [ ID #1938642 ]

Re: gridview and arraylist

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


"John Devlon" <johndevlon [at] hotmail.com> wrote in message
news:op.t9cl9nv895o8pp [at] laptoptim.wag325n...

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
Eliyahu Goldin [ Mi, 09 April 2008 17:09 ] [ ID #1938643 ]

Re: gridview and arraylist

Hi,

I've tried changing the list definition to

Dim mylist As New List(Of clsPerson)

.... but it doesn't seem to work..

The same error occures...

Does anyone have an idea?

Thanx

John
John Devlon [ Do, 10 April 2008 00:39 ] [ ID #1939320 ]
Microsoft » microsoft.public.dotnet.framework.aspnet » gridview and arraylist

Vorheriges Thema: C# or VB.NET?
Nächstes Thema: Page.PreviousPage