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

ParentGrid lost after ChildGrid's Expand event

1 Answer 36 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prava kafle
Top achievements
Rank 1
Prava kafle asked on 23 Nov 2011, 09:36 PM
Hi,
I am creating  a  dynamic nested  grid  to replicate grid displayed in following site.
 http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplate/defaultcs.aspx

When I expand  an item in child grid to display grandChild grid, the nestedview template on top level  is empty and  I lose all controls. How can I persist nested grids  on post back.


Here is my code to create root grid, child grid is also created with same logic.

1.
  protected void Page_Init(object source, System.EventArgs e)
        {
            try
            {      
                RadGrid rootGrid = CreateDynamicGrid("Ticket");
                NGridPlaceHolder.Controls.Add(rootGrid);
            }
            catch(Exception ex)
            {
                WIMProject.ShowMessageBox(ex.ToString());
            }
        }


2.
 public RadGrid CreateDynamicGrid(string tableName)
        {
            RadGrid radGrid = new RadGrid();
            try
            {
                radGrid.ID = tableName + "_RootGrid";
                radGrid.AutoGenerateColumns = true;
                radGrid.PageSize = 20;
                radGrid.MasterTableView.AllowPaging = true;
                radGrid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
                radGrid.MasterTableView.DataKeyNames = new string[] {"ID" };
                radGrid.MasterTableView.HierarchyLoadMode = GridChildLoadMode.ServerOnDemand;
                radGrid.MasterTableView.TableLayout = GridTableLayout.Auto;
                radGrid.MasterTableView.NestedViewTemplate = new NestedGridTemplate();
                radGrid.ItemCommand += new GridCommandEventHandler(radGrid_ItemCommand);
                radGrid.ItemDataBound += new GridItemEventHandler(radGrid_ItemDataBound);

              radGrid.NeedDataSource += new GridNeedDataSourceEventHandler(radGrid_NeedDataSource);

        .........}


3.
        void radGrid_ItemDataBound(object sender, GridItemEventArgs e)
        {
                  string gridID = e.Item.OwnerID;
                  string tableName = gridID.Replace("_RootGrid", "");

                  if (e.Item.GetType() == typeof(GridDataItem) && e.Item.Expanded)
                      {
                          GridDataItem currentDataItem = (e.Item as GridDataItem);
                          string selectedRowID = currentDataItem.GetDataKeyValue("ID").ToString();

                          Panel currentPanel = new Panel();
                          currentPanel.CssClass = "GridWrapperPanel";

                          NestedGridTemplate nestedGridTemplate = new NestedGridTemplate();
                          nestedGridTemplate.CreateTabStrip(tableName, currentPanel, selectedRowID);

                         (currentDataItem as GridDataItem).ChildItem.NestedViewCell.Controls.Add(currentPanel);
                      }
           
        }


Thanks,
Prava

1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 24 Nov 2011, 03:17 PM
Hello Prava,

Please refer to the code library below which elaborates on this subject and see if it helps to resolve this problem:
http://www.telerik.com/community/code-library/aspnet-ajax/grid/programmatic-creation-of-radgrid-hierarchy-with-templates.aspx

Best wishes,
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
Prava kafle
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or