I have a List of complex objects containing other objects within that I give as the data source to a gridview.(currently I'm using BoundFields for the columns). I need to bind data to the columns from the objects within at run time. How can this be done?
views:
26answers:
1
A:
We use LINQ to flatten (denormalise) the entity graph. You can use an anonymous class something like this
var viewList = (from entity in entityList
select new
{
Field1 = entity.Field1,
Field2 = entity.Relation.AnotherField,
Field3 = entity.Field3 + entity.Relation.YetAnotherField
}
).ToList();
myGridView.DataSource = viewList;
myGridView.DataBind();
And then use Field1, Field2 on the GridView etc for the data bindings
nonnb
2010-07-16 11:43:39
thanks nonnb!. This looks like it'll definitely work
Danaja
2010-07-19 05:17:40