gridview and arraylist
am 09.04.2008 16:49:00 von 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 =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
Re: gridview and arraylist
am 09.04.2008 16:52:25 von John Devlon
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
Re: gridview and arraylist
am 09.04.2008 17:07:32 von Matthijs Krempel
Hi John,
Is the name property public?
It's also better to use a generic list, like: List
With kind regards,
Matthijs Krempel
"John Devlon" schreef in bericht
news:op.t9cl9nv895o8pp@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
>
>
>
Re: gridview and arraylist
am 09.04.2008 17:09:35 von 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
"John Devlon" wrote in message
news:op.t9cl9nv895o8pp@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
Re: gridview and arraylist
am 10.04.2008 00:39:34 von John Devlon
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