Accessing parent RadGrid's Controls in usercontrol popup

2 posts, 0 answers
  1. Pradeep Enugala
    Pradeep Enugala avatar
    55 posts
    Member since:
    Apr 2010

    Posted 12 May 2010 Link to this post

    I have a 3-level RadGrid. In the MasterTable (ParentGrid), there's a template column with a label (LocationID). The detailtable(ChildGrid) has a commandItemTemplate "Add Contact". EditMode = popup. The popup is a usercontrol having a RadGrid(radGrid_CompanyContactDetails).

    Suppose there are 3 rows in the MasterTable.  I click on a row. Then I click on "Add Contact" of the detail table, it opens the popup. Here I want to access the parent Grid's LocationID value for that particular row from the usercontrol's RadGrid's ItemDataBound event. I am able to access the RadGrid if I have the following code:

     protected void radGrid_CompanyContactDetails_ItemDataBound(object sender, GridItemEventArgs e) 
            if (e.Item is GridDataItem) 
                GridDataItem item = (GridDataItem)e.Item; 
                radGrid rGrid = (Telerik.Web.UI.RadGrid)(item.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent); 
                Label location = (Label)rGrid.FindControl("LocationID") // Returns null

    But if I give rGrid.FindControl("LocationID"), it returns null.

    Please give some pointers on how to access the parent RadGrid's column values (or controls)
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 12 May 2010 Link to this post

    Hello Pradeep,

    The following code will help you to access the control placed in parent grid's item when insert/edit form open in detailtable.

    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
            if (e.Item is GridEditFormItem && e.Item.IsInEditMode && e.Item.OwnerTableView.Name=="DetailTableView1"
                GridEditFormItem editForm = (GridEditFormItem)e.Item; 
                GridDataItem item = (GridDataItem)editForm.OwnerTableView.ParentItem; // corresponding item in parentGrid
                Label lbl = (Label)item.FindControl("LocationID"); 

    Also the documenataion shows how to distinguish grid rows in hierarchy on ItemCreated/ItemDataBound.


Back to Top