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

[Solved] Hierarchical Grid Data Binding

2 Answers 127 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Carl
Top achievements
Rank 1
Carl asked on 20 May 2009, 01:51 PM
Hi,

I am trying to programatically create a grid. The grid is data bound to an IList<objA> - that bit is fine. The problem lies with creating the details tables, the data I want in the detail tables is actually a property of objA and is also an IList<objB> objB does have a property that relates it to objA. What I dont want to do is refactor the current design of the app to have to not use the above object model.

How do I do this please?

Thank you in advance,
Carl.

2 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 25 May 2009, 10:40 AM
Hello Carl,

In this case I suggest that you bind your hierarchical grid programmatically. Thus in the DetailTableDataBind event you can assign the corresponding list to the grid item detail table.
You can review the below online demo and help topic for more information:

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/detailtabledatabind/defaultcs.aspx
http://www.telerik.com/help/aspnet-ajax/grdHierarchicalDataBindingUsingDetailTableDataBind.html

Sincerely yours,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Carl
Top achievements
Rank 1
answered on 27 May 2009, 09:38 AM

This worked a treat. Thank you very much - your support and documentation has been outstanding as usual.

Here is a rough code example of how I acheived the solution;

protected void grdData_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)   
{  
    GridDataItem parent = e.DetailTableView.ParentItem as GridDataItem;   
 
    IList<objA> dataSource = e.DetailTableView.DataSource as IList<objA>; // this is all the data items in the datasource  
 
    // get the specific parent object   
    objA parentObj = dataSource.Single(delegate(objA a) { return a.ID == Convert.ToInt32(parent["ID"].Text); });   
 
    if (parentObj != null)   
    {  
        e.DetailTableView.DataSource = parentObj.ChildObjects;  
    }  
}  
 
public class objA  
{  
    public int ID { getset; }  
    public IList<objB> ChildObjects;  
}  
 
public class objB  
{  
    public int ID { getset; }  
Tags
Grid
Asked by
Carl
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Carl
Top achievements
Rank 1
Share this question
or