Multiple Entity Framework 4 Entities & OnNeedDataSource

2 posts, 1 answers
  1. Richard Weeks
    Richard Weeks avatar
    95 posts
    Member since:
    Oct 2009

    Posted 01 Mar 2011 Link to this post

    Hi, how can I bind a RadGrid when I need to include details from more than one entity?

    I have the following code that runs, definitely brings back data but does not show anything in my grid (with AutoGenerateColumns set to "true"):

    protected void MyGrid_OnNeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        using (var context = new MyContainer())
        {
            var d = from data in context.ParentEntity.Include("ChildEntities"
                    select new
                    {
                        data.ParentProperty, 
                        data.ChildEntity.FirstOrDefault().ChildProperty
                    };
      
            this.MyGrid.DataSource = d.ToList();
        }
    }

    I don't mind admitting my LINQ to Entities knowledge is "ongoing" but you can see what I am trying to do: for every ParentEntity, get me their properties and for every ChildEntity under that, get me their properties as well. I want the grid to display those.

    Because the ChildEntity may not necessarilly immediately have a ParentEntity, I can't do a master / detail view with two grids.

    Richard
  2. Answer
    Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 04 Mar 2011 Link to this post

    Hello Richard,

    To display hierarchical data, RadGrid renders one or more detail tables for each item (row) in the MasterTableView. In a multi-level hierarchy, each item of every detail table can have one or more detail tables as well. The level of the grid hierarchy can be arbitrarily deep.

    When binding each detail table view, RadGrid fires the DetailTableDataBind event. The argument for a DetailTableDataBind event handler carries all the information you need for binding the detail table, including the table view that should be bound, its parent item, and so on. Please refer to this help article for more information.


    I hope this gets you started properly.

    Greetings,
    Pavlina
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top