I would like to create a Hierachical grid programatically. According to Telerik manuals http://www.telerik.com/help/aspnet-ajax/grdprogrammaticcreation.html
im using the following code, The only code i changed is to replace datasourceid with datasource cause im using datasets to load data. and at the end im loading the grid to a panel3. Does anyone see what im doing wrong here?
protected void Page_Init(object sender, System.EventArgs e)
{
DefineGridStructure();
}
private void DefineGridStructure()
{
RadGrid grid = new RadGrid();
grid.ID =
"RadGrid1";
grid.DataSource = dsData2;
grid.Skin =
"Inox";
grid.Width =
Unit.Percentage(100);
grid.PageSize = 5;
grid.AllowPaging =
true;
grid.PagerStyle.Mode =
GridPagerMode.NextPrevAndNumeric;
grid.AutoGenerateColumns =
false;
//Add Location
grid.MasterTableView.PageSize = 15;
grid.MasterTableView.Width =
Unit.Percentage(100);
grid.MasterTableView.DataKeyNames =
new string[] { "LocationID" };
GridBoundColumn boundColumn = new GridBoundColumn();
boundColumn.DataField =
"LocationID";
boundColumn.HeaderText =
"LocationID";
grid.MasterTableView.Columns.Add(boundColumn);
boundColumn =
new GridBoundColumn();
boundColumn.DataField =
"Location";
boundColumn.HeaderText =
"Contact Name";
grid.MasterTableView.Columns.Add(boundColumn);
//Add Sublocation
ableView tableViewOrders = new GridTableView(grid);
tableViewOrders.DataSource = dsData;
tableViewOrders.Width =
Unit.Percentage(100);
GridRelationFields relationFields = new GridRelationFields();
relationFields.MasterKeyField =
"LocationID";
relationFields.DetailKeyField =
"ParentLocationID";
tableViewOrders.ParentTableRelation.Add(relationFields);
boundColumn =
new GridBoundColumn();
boundColumn.DataField =
"LocationID";
boundColumn.HeaderText =
"LocationID";
tableViewOrders.Columns.Add(boundColumn);
boundColumn =
new GridBoundColumn();
boundColumn.DataField =
"Location";
boundColumn.HeaderText =
"Location";
tableViewOrders.Columns.Add(boundColumn);
grid.MasterTableView.DetailTables.Add(tableViewOrders);
// Add the grid to the placeholder
this.Panel3.Controls.Add(grid);
}
Please note that i can design both the master table and the detailtable at design time and it works fine but i want to do it in code behind for flexibility and thats what is giving me problems.