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

Creating Hierarchical RadGrid via Code

1 Answer 21 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Munish
Top achievements
Rank 1
Munish asked on 02 Jul 2012, 02:33 AM
Hello Team,
I am facing problem in dynamic creation grid structure and bind data and not able to see nested grid data below is code for same. Please do help me asap.

Looking forward to your response.


RadGridData.AutoGenerateColumns = false;

            //generate grid columns/ grid structure
            GridBoundColumn ZoneColumn;
            GridTableView gridTableView = new GridTableView();
            for (int ColumnCount = 0; ColumnCount < ZoneData.Tables[0].Columns.Count; ColumnCount++)
            {
                ZoneColumn = new GridBoundColumn();
                RadGridData.MasterTableView.Columns.Add(ZoneColumn);
                ZoneColumn.DataField = Convert.ToString(ZoneData.Tables[0].Columns[ColumnCount]);
                ZoneColumn.HeaderText = Convert.ToString(ZoneData.Tables[0].Columns[ColumnCount]);
                ZoneColumn.UniqueName = Convert.ToString(ZoneData.Tables[0].Columns[ColumnCount]);
                ZoneColumn.SortExpression = Convert.ToString(ZoneData.Tables[0].Columns[ColumnCount]);

                gridTableView.AutoGenerateColumns = false;
                for (int innerColumnCount = 0; innerColumnCount < ZoneData.Tables[1].Columns.Count; innerColumnCount++)
                {
                    ZoneColumn = new GridBoundColumn();
                    gridTableView.Columns.Add(ZoneColumn);
                    ZoneColumn.DataField = Convert.ToString(ZoneData.Tables[1].Columns[innerColumnCount]);
                    ZoneColumn.HeaderText = Convert.ToString(ZoneData.Tables[1].Columns[innerColumnCount]);
                    ZoneColumn.UniqueName = Convert.ToString(ZoneData.Tables[1].Columns[innerColumnCount]);
                    ZoneColumn.SortExpression = Convert.ToString(ZoneData.Tables[1].Columns[innerColumnCount]);
                }
                RadGridData.MasterTableView.DetailTables.Add(gridTableView);
            }


            RadGridData.MasterTableView.AutoGenerateColumns = false;
            RadGridData.MasterTableView.DetailTables[0].AutoGenerateColumns = false;
            GridRelationFields relationFields = new GridRelationFields();
            relationFields.MasterKeyField = "ID";
            relationFields.DetailKeyField = "ID";
            gridTableView.ParentTableRelation.Add(relationFields);


            RadGridData.MasterTableView.DataSource = ZoneData.Tables["Zone"]; //ZoneData is dataset with table data
            RadGridData.MasterTableView.DetailTables[0].DataSource = ZoneData.Tables["ZoneContract"];



Thanks & Regards

1 Answer, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 04 Jul 2012, 08:47 AM
Hello Munish,

Please check out the following resources:
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html (Create hierarchical grid programmatically section)
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/hierarchy/defaultcs.aspx

I hope this helps.

Regards,
Radoslav
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
Chart (Obsolete)
Asked by
Munish
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or