RowDataBound and the Generic List! You know you’re curious.

The Generic list is becoming my best friend although I couldn’t conclusively tell you why I’m enjoying using it more than a standard dataset.  At any rate, one of the issues I ran into with the Generic list was reference fields on a GridView’s RowDataBound event.

With a dataset you would reference a field this way:


But when using a generic list you’ll get an error along the lines of

No default member found for {myclass}

Here’s how to set up the RowDataBound event when using a Generic List.

If e.Row.RowType = DataControlRowType.DataRow Then
  Dim obj As MyNameSpace.MyListInfo = CType(e.Row.DataItem, MyNameSpace.MyListInfo)
  Dim myVal as string = obj.MyField

  --any other code here---
End If

In this case “MyNameSpace” is the namespace…go figure…and MyListInfo is the class containing all the properties that correspond to fields in your table.

This is one of the reasons I love the list so much: I don’t have to remember all the names of the fields because they’ve all been turned into properties.

More to come on the Generic List!

Leave a Reply

Your email address will not be published. Required fields are marked *