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

Get TableView Name

4 Answers 203 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rohan
Top achievements
Rank 1
Rohan asked on 19 Jan 2011, 07:35 AM
Hi,

I have a dynamically created RadGrid. Now on expanding the child tables in the Grid, I want to get the name of the tableView on "grv_ItemCommand" event. Here is my code:
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);
 
            GridTableView tab = new GridTableView(grv);
            switch (tableView.Name)
            {
                case "Buildings":
                    tab.DataMember = "Floors";
                    tab.Name = "Floors";
                    tableView.DetailTables.Clear();
                    tableView.DetailTables.Add(tab);
                    break;
 
                case "Floors":
                    tab.DataMember = "Rooms";
                    tab.Name = "Rooms";
                    tableView.DetailTables.Clear();
                    tableView.DetailTables.Add(tab);
                    break;
 
                default:
                    break;
            }
 
            if (tableView.Name == "Buildings")
            {
                GridTableView subTab = new GridTableView(grv);
                if (tab.Name == "Floors")
                {
                    subTab.DataMember = "Rooms";
                    subTab.Name = "Rooms";
                    tab.DetailTables.Clear();
                    tab.DetailTables.Add(subTab);
                }
 
            }
 
            grv.DataBind();
        }
 
protected void grv_ItemCommand(object sender, GridCommandEventArgs e)
        {
            BindDetails(ParentEntity.ParentEntityId);
            HttpContext.Current.Session["id"] = ParentEntity.ParentEntityId;
            switch (Session["type"].ToString())
            {
                case "All Categories":
                    FormExtenderControl1.EntityType = new BaseEntities(BaseEntities.SpaceCategories);
                    break;
 
                case "SpaceCategories":
                    FormExtenderControl1.EntityType = new BaseEntities(BaseEntities.SpaceBuildings);
                    break;
 
                case "SpaceBuildings":
                    FormExtenderControl1.EntityType = new BaseEntities(BaseEntities.SpaceFloors);
                    break;
 
                case "SpaceFloors":
                    FormExtenderControl1.EntityType = new BaseEntities(BaseEntities.SpaceRooms);
                    break;
 
                default:
                    throw new Exception("Unable to identify Entity.");
            }
 
            clickedType = Session["type"].ToString();
 
            if (e.CommandName == "Modify")
            {
                btnSave.CommandName = "Modify";
                int id = GetID();
                FormExtenderControl1.EntityPrimaryKeyId = id;
                FormExtenderControl1.DataBind();
                mdlPopup.Show();
            }
 
            if (e.CommandName == "Delete")
            {
                int id = GetID();
                FormExtenderControl1.Delete(id);
                BindData();
            }
 
            if (e.CommandName == "Add")
            {
                btnSave.CommandName = "Add";
                FormExtenderControl1.EntityPrimaryKeyId = -1;
                FormExtenderControl1.DataBind();
                mdlPopup.Show();
            }
        }
 
        private Int32 GetID()
        {
             
            foreach (GridDataItem dataItem in grv.MasterTableView.DetailTables.OwnerGrid.Items)
            {
                 
                if (dataItem.Selected == true)
                {
                    Int32 ID = Int32.Parse(dataItem["Id"].Text);
                    return ID;
                }
            }
                        
            throw new ArgumentNullException("Id Not found");
        }
Please assist me....


thanks
Rohan

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Jan 2011, 08:19 AM
Hello Rohan,

You can get the TableViewName by using following code snippet:

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
   {
          .  .   .   .   .   .
       string tableViewName = e.Item.OwnerTableView.Name;
    }

Thanks,
Princy.
0
Rohan
Top achievements
Rank 1
answered on 19 Jan 2011, 08:39 AM
Hi Princy,

Thanks for replying. I tried with what you suggested but didn't work. Its coming as a empty string.



Thanks
Rohan


 
0
Princy
Top achievements
Rank 2
answered on 20 Jan 2011, 06:24 AM
Hello Rohan,

Please check whether you have set Name property for GridTableView.

C#:
GridTableView tableViewOrders = new GridTableView(RadGrid1);
 tableViewOrders.Name = "GridTableView1";

Thanks,
Princy.
0
Rohan
Top achievements
Rank 1
answered on 20 Jan 2011, 06:30 AM
Hi Princy,

Thanks for replying. I have given the table name. But now I did it by using "data member" attribute of the table view.
Thanks for your help.


Thanks
rohan
Tags
Grid
Asked by
Rohan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Rohan
Top achievements
Rank 1
Share this question
or