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

hierarchy in radGrid

1 Answer 50 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rohan
Top achievements
Rank 1
Rohan asked on 18 Jan 2011, 06:03 AM
Hi to all,

I am trying to define heirarchy in radgrid programmatically. I am able to get it at the first level and not after that. Here is what I have done:
private void BindData()
        {
            clickedType = Session["type"].ToString();
            int id = ParentEntity.ParentEntityId;
            GridTableView tableView = new GridTableView(grv);
             
            switch (clickedType)
            {
                case "All Categories":
                    using (SpaceCategoriesService.SpaceCategoriesServiceClient s = new SpaceCategoriesService.SpaceCategoriesServiceClient())
                    {
                        grv.DataSource = s.GetCategoryTable();
                        tableView.Name = "Buildings";
                        tableView.DataMember = "Buildings";
                    }
                    break;
 
                case "SpaceCategories":
                    using (SpaceBuildingsService.SpaceBuildingsServiceClient s = new SpaceBuildingsService.SpaceBuildingsServiceClient())
                    {
                        grv.DataSource = s.GetBuildingByCategoryId(id);
                        tableView.Name = "Floors";
                        tableView.DataMember = "Floors";
                    }
                    break;
 
                case "SpaceBuildings":
                    using (SpaceFloorService.SpaceFloorServiceClient s = new SpaceFloorService.SpaceFloorServiceClient())
                    {
                        grv.DataSource = s.GetFloorsByBuildingId(id);
                        tableView.Name = "Rooms";
                        tableView.DataMember = "Rooms";
                    }
                    break;
 
                case "SpaceFloors":
                    using (SpaceRoomService.SpaceRoomServiceClient s = new SpaceRoomService.SpaceRoomServiceClient())
                    {
                        grv.DataSource = s.GetRoomByFloorId(id);
                    }
                    break;
 
                default:
                    throw new Exception("Unable to identify Entity.");
            }
 
            grv.MasterTableView.DetailTables.Clear();
            grv.MasterTableView.DetailTables.Add(tableView);
            grv.DataBind();
 
            foreach (GridDataItem item in grv.Items)
            {
                if (tableView.Name != "")
                {
                                         
                    LinkButton lnkExpand = (LinkButton)grv.Items[item.ItemIndex].FindControl("lnkExpand");
                    lnkExpand.Text = "Show " + tableView.Name;
                     
                }
                 
            }
            GridTableView tab = new GridTableView(grv);
            tab.DataMember = "Rooms";
            tab.Name = "Rooms";
            tableView.DetailTables.Clear();
            tableView.DetailTables.Add(tab);
 
        }
 
        protected void grv_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
        {
            try
            {
                GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
                 
                string datamem = e.DetailTableView.DataMember;
 
                if (!string.IsNullOrEmpty(e.DetailTableView.DataMember))
                {
 
                    switch (e.DetailTableView.DataMember)
                    {
                        case "Buildings":
                            int CategoryID = int.Parse(dataItem.GetDataKeyValue("Id").ToString());
                            DataTable buildings;
                            using (SpaceBuildingsService.SpaceBuildingsServiceClient s = new SpaceBuildingsService.SpaceBuildingsServiceClient())
                            {
                                buildings = s.GetBuildingByCategoryId(CategoryID);
                            }
                            e.DetailTableView.DataSource = buildings;
                            break;
 
                        case "Floors":
                            int BuildingID = int.Parse(dataItem.GetDataKeyValue("Id").ToString());
                            DataTable floors;
                            using (SpaceFloorService.SpaceFloorServiceClient s = new SpaceFloorService.SpaceFloorServiceClient())
                            {
                                floors = s.GetFloorsByBuildingId(BuildingID);
                            }
                            e.DetailTableView.DataSource = floors;
                            break;
 
                        case "Rooms":
                            int FloorID = int.Parse(dataItem.GetDataKeyValue("Id").ToString());
                            DataTable rooms;
                            using (SpaceRoomService.SpaceRoomServiceClient s = new SpaceRoomService.SpaceRoomServiceClient())
                            {
                                rooms = s.GetRoomByFloorId(FloorID);
                            }
                            e.DetailTableView.DataSource = rooms;
                            break;
 
                        default:
                            break;
                    }
 
                }
 
            }
            catch (Exception ee)
            {
                string asd = ee.Message;
                //throw new Exception("Unable to load!");
            }
        }

At the second level I am getting the exception "Index out of range". Please assist me....

cheers
rohan

1 Answer, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 19 Jan 2011, 10:58 AM
Hi Rohan,

 You can have a look at this demo showing Programmatic Creation of Hierarchy and modify it according to your needs.

Greetings,
Marin
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Rohan
Top achievements
Rank 1
Answers by
Marin
Telerik team
Share this question
or