Databinding to ASP.NET Datagrid

Posts   
 
    
nilzzz
User
Posts: 1
Joined: 29-Apr-2005
# Posted on: 29-Apr-2005 17:19:24   

Hi

I have a problem that I can't seem to solve. Maybe its because its almost weekend, but I need som info on this one. What is the best practice for binding related informasjon between two tables in one datagrid? I have two tables, Person and Role. I want a liste with the Persons info, and the Role.Name from the Role table. The tables are related 1:n


DataAccessAdapter adapter = new DataAccessAdapter();
EntityCollection persons= new EntityCollection(new DALA.FactoryClasses.PersonEntityFactory());
DALH.IPrefetchPath2 prefetchPath = new DALH.PrefetchPath2((int)EntityType.PersonEntity);
prefetchPath.Add(PersonEntity.PrefetchPathRole);
adapter.FetchEntityCollection(persons,null,prefetchPath);
DataGrid1.DataSource = persons;
DataGrid1.DataBind()

How can I get Role.Name from the Role table in the datagrid? I get an error message stating:

A field or property with the name 'Role.Name' was not found on the selected datasource. I am using a template column, with DataBinder.Eval and referencing the object Container, "DataItem.Role.Name"

Any help would be greatly appreciated

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 29-Apr-2005 17:45:11   

Please cast DataItem to PersonEntity:

((PersonEntity)DataItem).Role.Name

Frans Bouma | Lead developer LLBLGen Pro