Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
535
Binding grid to LINQ
posted

I am binding a grid to a linq statement which creates an anonymous type class for the data. When I try and get to the data in the InitializeRow event, I'm having a problem casting the row properly. If I create a class for the linq results, it's easy, but I don't want to create a new class for every linq statement. For example:

var rows= from r in db.table select new {id=xxxx, value=yyyy}  <-- this creates an anonymous type versus....

var rows= from r in db.table select rowclass new {id=xxxx, value=yyyy}

class rowclass {int id, string yyyy}, which gives me a collection of rowclass.

Any ideas on how to access the data when using anonymous classes? thanks.

Parents
No Data
Reply
  • 625
    posted

    Not sure exactly what you are trying to do, but I have some code which needs to get access to the row data in the InitializeRow event.

    I simply use code like

    dim strName as string = e.row.Cells(0).Text

    This returns the string in the first column of the row.

    This code works for a LINQ query from both XML and SQL.

    Not sure if this of any help

    Alex

Children