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

Accessing parent RadGrid's Controls in usercontrol popup

1 Answer 162 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Pradeep Enugala
Top achievements
Rank 1
Pradeep Enugala asked on 12 May 2010, 08:34 AM
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)

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 May 2010, 09:47 AM
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.

C#:
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.

Regards
Shinu.



Tags
General Discussions
Asked by
Pradeep Enugala
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or