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

Howto update all details rows when Master row is updated

3 Answers 126 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric Krauska
Top achievements
Rank 1
Eric Krauska asked on 07 Jan 2009, 10:20 PM
I have a master detail radGrid.  I need to programmatically update all detail rows when a column changes in the master table.  Is there a demo or something that will assist me in how to gather all child rows?  I'm able to extract the updated row from e.Item in the ItemUpdated event, but I can't figure out how to access all child rows.  Do I need to go to the datasource or does radGrid provide me with access via the object model?

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Jan 2009, 09:33 AM
Hello Eric

You can try out the following code to access the child rows for a parent row:
cs:
  protected void RadGrid1_ItemUpdated(object source, GridUpdatedEventArgs e) 
    { 
        GridDataItem item = (GridDataItem)e.Item;         
        { 
            if (item.Expanded) 
            { 
                GridTableView nestedView = (GridTableView)item.ChildItem.NestedTableViews[0]; 
 
                foreach (GridDataItem item1 in nestedView.Items) // detail table rows
                { 
                    string strtxt = item1["ChildColumnUniqueName"].Text; 
                } 
            } 
        } 
    } 

Thanks
Princy.
0
Eric Krauska
Top achievements
Rank 1
answered on 03 Feb 2009, 08:58 PM
sorry for the delay in getting back to you for this post.  I get the following exception when using your code:

Unable to cast object of type 'Telerik.Web.UI.GridEditFormItem' to type 'Telerik.Web.UI.GridDataItem'.

Please notice I am not using incell editing.  As you can see, I'm using EditMode="PopUp". 



0
Sebastian
Telerik team
answered on 04 Feb 2009, 07:59 AM
Hello Eric,

Inside the ItemUpdated handler of the grid the type of e.Item will be GridEditableItem or GridEditFormItem, therefore you will need to modify the code as follows:

protected void RadGrid1_ItemUpdated(object source, GridUpdatedEventArgs e)    
    {    
        GridEditFormItem editItem = e.Item as GridEditFormItem;  
        GridDataItem item = editItem.ParentItem as GridDataItem;            
        {    
            if (item.Expanded)    
            {    
                GridTableView nestedView = (GridTableView)item.ChildItem.NestedTableViews[0];    
    
                foreach (GridDataItem item1 in nestedView.Items) // detail table rows  
   
                {    
                    string strtxt = item1["ChildColumnUniqueName"].Text;    
                }    
            }    
        }    
    }    
 

Further information about the auto-generated edit forms mode of RadGrid and the relation between the edited item and its non-editable parent item can be gathered from this documentation article.

Kind regards,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Eric Krauska
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Eric Krauska
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or