SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2001
    Location
    London
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Binding custom generic class list to Gridview

    I am trying to bind a generic list of users from my database to a gridview instead of using a dataset. I can build the generic list fine and reiterate through them one by one using the below:

    Dim allusers as list(of MyUser) = myuser.getallusers()

    For each myUser as MyUser in allusers

    Next

    However, when I bind this to a Gridview I know the correct number of records are showing, but I do not see the data for each row.... I am using a mixture of bound and templated columns in my Gridview, e.g.:

    <asp:BoundField ItemStyle-Width="15%" SortExpression="CreatedDateTime" HeaderText="Created Date" DataField="CreatedDateTime" HeaderStyle-HorizontalAlign="left" ReadOnly="true" />

    But for this column I only get the default date of 01/01/1900 etc...

    On the RowDataBound event I have used both the following to get each instance of the object, but without any luck!

    Dim UserId As Integer = CType(e.Row.DataItem, MyWebApp.AppUser).UserId

    Dim oUser as AppUser = ctype(e.row.dataitem, MyWebApp.AppUser)

    What am I doing wrong?

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2001
    Location
    London
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My oversight this has been sorted now...

    I forgot to add a constructor to the myuser class in order to load each users when using the datareader to grab the data....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •