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

Hierarchical Grid Problem

1 Answer 71 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Sean asked on 11 Jul 2008, 02:45 PM

I am trying to create a hierarchical grid using code. I have a dataset that contains two tables, 'Categories' and 'Items'. The table 'Categories' has a field 'mastercategoryid' and the table 'Items' has a column 'categoryid'.

I am trying to build the grid as follows:

protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    FoodVanWCF wcf = new FoodVanWCF();
    DataSet menu = wcf.GetMenu();    
    RadGrid1.DataSource = menu.Tables["Categories"];
    RadGrid1.MasterTableView.DetailTables[0].DataSource = menu.Tables["Items"];
    RadGrid1.MasterTableView.DataKeyNames = new string[] { "mastercategoryid" };
    RadGrid1.MasterTableView.DetailTables[0].DataKeyNames = new string[]{ "categoryid" };

    GridRelationFields grf = new GridRelationFields();

    grf.MasterKeyField = "mastercategoryid";
    grf.DetailKeyField = "categoryid";



However when I try to expand the grid I get the error

Parent table relations set, but no correspoding data-key name found

What am I doing wrong here?

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 14 Jul 2008, 12:47 PM
Hi Sean,

Please refer to the following help article on creating the RadGrid structure dynamically in the code-behind:

Programmatic creation

Please note that the best approach is to define RadGrid's hierarchy when defining its structure (in the Page_Load or Page_Init events). Also if you need to programmatically set RadGrid's detail table data sources, you have a dedicated event at your disposal - DetailTableDataBind. For more information:

Hierarchical data-binding using DetailTableDataBind event

Sincerely yours,
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question