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

hierarchical grid will not expand to show child table and records

1 Answer 264 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Remi
Top achievements
Rank 2
Remi asked on 03 Oct 2011, 08:06 PM
Hello,

We're using 2010 Q3 and running into some issues when attempting a hierarchical grid.

This code is based on the demo. The issue is the expand won't show the child records / table when the arrow beside a parent record is clicked. Nothing happens. No error.

Here is some sample code.

private void DefineGridStructure()
        {
            /* Hierarchy Grid - lab and test types for each lab */

            RadGrid oRadGridLab = new RadGrid();

            oRadGridLab.ID = "TelRadGridLab";

            var oLaboratories
                = (from p in this.Core.EntityModel.Laboratories
                   select p).ToList();

            oRadGridLab.DataSource = oLaboratories;
            oRadGridLab.DataMember = "Laboratory";
           

            oRadGridLab.MasterTableView.DataKeyNames = new string[] { "Idn" };

            oRadGridLab.Skin = "Office2007";

            oRadGridLab.Width = Unit.Percentage(98);
            oRadGridLab.PageSize = 3;
            oRadGridLab.AllowPaging = true;
            oRadGridLab.AllowSorting = true;
            oRadGridLab.PagerStyle.Mode = GridPagerMode.NumericPages;
            oRadGridLab.AutoGenerateColumns = false;
            //oRadGridLab.MasterTableView.GroupLoadMode = GridGroupLoadMode.Client;

            oRadGridLab.MasterTableView.PageSize = 3;

            //Add columns
            GridBoundColumn boundColumn;
            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "Idn";
            boundColumn.HeaderText = "Idn";
            oRadGridLab.MasterTableView.Columns.Add(boundColumn);

            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "Name";
            boundColumn.HeaderText = "Name";
            oRadGridLab.MasterTableView.Columns.Add(boundColumn);

            oRadGridLab.DataBind();

            //Detail table - Test Types (II in hierarchy level)
            GridTableView oTableViewTestTypes = new GridTableView(oRadGridLab);

            var oTestTypes
                = (from p in this.Core.EntityModel.TestTypeToLaboratories
                   select p).ToList();

            oTableViewTestTypes.DataSource = oTestTypes;
            oTableViewTestTypes.DataMember = "TestTypeToLaboratory";         
                       
            oTableViewTestTypes.Width = Unit.Percentage(100);

            oTableViewTestTypes.DataKeyNames = new string[] { "Idn" };

            GridRelationFields relationFields = new GridRelationFields();
            relationFields.MasterKeyField = "Idn";
            relationFields.DetailKeyField = "LaboratoryIdn";
            oTableViewTestTypes.ParentTableRelation.Add(relationFields);

            oRadGridLab.MasterTableView.DetailTables.Add(oTableViewTestTypes);

            //Add columns
            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "LaboratoryIdn";
            boundColumn.HeaderText = "LaboratoryIdn";
            oTableViewTestTypes.Columns.Add(boundColumn);

            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "CreatedOn";
            boundColumn.HeaderText = "CreatedOn";
            oTableViewTestTypes.Columns.Add(boundColumn);

            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "ModifiedOn";
            boundColumn.HeaderText = "ModifiedOn";
            oTableViewTestTypes.Columns.Add(boundColumn);

            oTableViewTestTypes.DataBind();   

            //Add the RadGrid instance to the controls
            this.AspPlaceHolder.Controls.Add(oRadGridLab);
        }


Thank you in advance for your assistance and considerations.

1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 04 Oct 2011, 08:03 AM
Hi Remi,

Note that hierarchical grid structure is not supported with simple data-binding (calling DataBind()). To bind each detail table-view, Telerik RadGrid fires the DetailTableDataBind event. The argument carries all needed information such as the table that should be data bound, parent item(s), etc. Please refer to the online examples below for more information:
Programmatic Binding 
Creating Hierarchy Programmatically 

All the best,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Remi
Top achievements
Rank 2
Answers by
Pavlina
Telerik team
Share this question
or