gridview and arraylist

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Devlon

    #1

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

    myList.Add(myFi le)

    GridView1.DataS ource = myList
    GridView1.DataB ind()

    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

    #2
    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 = New clsPerson
    myPerson.Name = "John"
    >
    myList.Add(myPe rson)
    >
    GridView1.DataS ource = myList
    GridView1.DataB ind()
    Does anyone have an idea ? It's not working...

    John



    Comment

    • Matthijs Krempel

      #3
      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@hot mail.comschreef in bericht
      news:op.t9cl9nv 895o8pp@laptopt im.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(myPe rson)
      >>
      > GridView1.DataS ource = myList
      > GridView1.DataB ind()
      >
      Does anyone have an idea ? It's not working...
      >
      John
      >
      >
      >

      Comment

      • Eliyahu Goldin

        #4
        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]




        "John Devlon" <johndevlon@hot mail.comwrote in message
        news:op.t9cl9nv 895o8pp@laptopt im.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(myPe rson)
        >
        GridView1.DataS ource = myList
        GridView1.DataB ind()
        Does anyone have an idea ? It's not working...

        John




        Comment

        • John Devlon

          #5
          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

          Comment

          Working...