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";
RadGrid1.MasterTableView.DetailTables[0].ParentTableRelation.Add(grf);
}
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?