Creating Hierarchical RadGrid via Code

Thread is closed for posting
2 posts, 0 answers
  1. Munish
    Munish avatar
    13 posts
    Member since:
    Jul 2012

    Posted 01 Jul 2012 Link to this post

    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
  2. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 04 Jul 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top