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

Hierachical Grid not Loading

3 Answers 27 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Omlac
Top achievements
Rank 1
Omlac asked on 08 Oct 2008, 08:14 AM

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.

3 Answers, 1 is accepted

Sort by
0
Omlac
Top achievements
Rank 1
answered on 08 Oct 2008, 10:10 AM
Hie all,
When i add the placeholder the grid appeared, i dont have a problem with the place holder, i can still use it,
But the detail view isnt apearing , i can just see the master table. How can i fix this.
0
Omlac
Top achievements
Rank 1
answered on 08 Oct 2008, 11:38 AM
I have also noticed that the Mastertable is not behaving according to the lines of code i added,  

grid.AutoGenerateColumns =

false;
Its getting all the records from the select statement yet im adding only two columns in code.

 

0
Omlac
Top achievements
Rank 1
answered on 08 Oct 2008, 12:44 PM
Here was the problem 
When using datasets the first line cant come after the second line but with datasourceid its possible. Funny!!!
grid.AutoGenerateColumns = false;
grid.DataSource = dsData2;
so this is closed.
Tags
Grid
Asked by
Omlac
Top achievements
Rank 1
Answers by
Omlac
Top achievements
Rank 1
Share this question
or