This is a migrated thread and some comments may be shown as answers.

RadGrid Hierarchy with Object Model

3 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 03 Oct 2008, 04:07 AM
I've tried to search for this and I'm sure it's often requested but I've had no luck finding it via Google or in the docs or examples.  What I want to do is have a grid with hierarchy (something like <DetailTables>)

My object model I'm binding is an IList of Customers which look like this

Customer
  Id
  Name
  Locations typeof(IList)

Each customer should be at the top level of the grid, when the user expands the grid it should return locations.  I've tried to set the DataMember of the DetailTable with no luck.

Most of the examples I see uses SQL statements on the ASPX page, however I already have an object model that's already populated.  I'm using NHibernate but this would be the same as if you were using Entity Framework (EF).  Any help is appreciated.

Thanks

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 03 Oct 2008, 05:57 AM
Hello Scott,

Please check my blog post to know how to achieve this:
http://blogs.telerik.com/VladimirEnchev/Posts/08-08-11/How_To_RadGrid_hierarchy_from_objects_hierarchy.aspx

Kind regards,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Scott
Top achievements
Rank 1
answered on 03 Oct 2008, 03:47 PM
Great that works, my code looks like this:
        protected void CustomersGrid_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
        {
                    e.DetailTableView.DataSource = ((List<LegalEntity>) e.DetailTableView.DataSource).Find(
                        cust => cust.Id == Convert.ToInt32(e.DetailTableView.ParentItem.GetDataKeyValue("Id"))
                        ).Locations;


One more question, can I bind multiple levels in the grid like this?  I don't see how the RadGrid supports more than one level (i.e. Children have Children)

Thanks
0
Sebastian
Telerik team
answered on 06 Oct 2008, 07:37 AM
Hi Scott,

You can check the Name property of the detail table which is about to be bound inside the DetailTableDataBind event handler (note that this property should be set to have unique value beforehand). Review the online demo of RadGrid concerning hierarchy creation with DetailTableDataBind handling for more details:

http://demos.telerik.com/ASPNET/Prometheus/Grid/Examples/Programming/DetailTableDataBind/DefaultCS.aspx

Best regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Scott
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Scott
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or