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

Refresh parent grid when detail grid updates

4 Answers 299 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ed Lance
Top achievements
Rank 1
Ed Lance asked on 19 Aug 2010, 12:16 AM
I have a RadGrid with a master table and a details table in a hierarchy.  The master shows totals from the data in the details table. 

I can edit a row in the details grid and save it without problems.  But the total on the master row is then incorrect.  I added code to rebind, which works, but then the details grid won't go out of edit mode.

In ItemCommand I check to see if it is the detail table, then do this:
e.Item.OwnerTableView.ParentItem.OwnerTableView.Rebind()

I also tried that line in the Item_Updated event, with the same result.

So how do you cause the master grid to refresh and get the detail grid to exit edit mode?

Thanks

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Aug 2010, 08:41 AM
Hello,

You can try the following code snippet in Item_Updated event to achieve this.

C#:
protected void RadGrid1_ItemUpdated(object source, GridUpdatedEventArgs e)
    {
        GridEditFormItem insertItem = (GridEditFormItem)e.Item;
        insertItem.OwnerTableView.ClearEditItems();
        insertItem.OwnerTableView.Rebind();
        RadGrid1.Rebind();
    }

Thanks,
Princy.
0
Ed Lance
Top achievements
Rank 1
answered on 19 Aug 2010, 05:49 PM
Thanks, that worked.  Doesn't look like you need the first rebind statment.

The only issue with this is that the detail grid doesn't stay expanded.  You have to find the row in the master table and expand it again.  My client won't be real happy about that.
0
Accepted
Princy
Top achievements
Rank 2
answered on 20 Aug 2010, 07:23 AM
Hello,

In order to achieve this in ItemCommand event, store the MasterTable row index in a session variable and in ItemUpdated event exapand the corresponding row after rebinding.

C#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {      
        if ( e.CommandName == "Edit")
        {
            if (e.Item.OwnerTableView.Name == "GridTableView1") //check with the name of DetailTable
            Session["rowIndex"] = e.Item.OwnerTableView.ParentItem.ItemIndex;
        }
   }
    
 protected void RadGrid1_ItemUpdated(object source, GridUpdatedEventArgs e)
    {
        int rowIndex = Convert.ToInt16(Session["rowIndex"].ToString());
        GridEditFormItem insertItem = (GridEditFormItem)e.Item;
        insertItem.OwnerTableView.ClearEditItems();
        insertItem.OwnerTableView.Rebind();
        RadGrid1.Rebind();
        if (e.Item.OwnerTableView.Name == "GridTableView1") //check if its DetailTable
        RadGrid1.MasterTableView.Items[rowIndex].Expanded = true;
      }

Thanks,
Princy.
0
Ed Lance
Top achievements
Rank 1
answered on 21 Aug 2010, 12:32 AM
Thanks, that did what I needed.  I put the row index in a class level variable since it will be used in the same life cycle later.

Also, note that the code in ItemUpdated also has to be run in ItemInserted.

Protected Sub SummaryGrid_ItemUpdated(ByVal source As Object, ByVal e As Telerik.Web.UI.GridUpdatedEventArgs) Handles SummaryGrid.ItemUpdated
    'Need to rebind the master table
    e.Item.OwnerTableView.ClearEditItems()
    SummaryGrid.MasterTableView.Rebind()
    If e.Item.OwnerTableView.Name = "WSTable" Then 'check if its DetailTable
        SummaryGrid.MasterTableView.Items(mintParentID).Expanded = True
    End If
End Sub
Tags
Grid
Asked by
Ed Lance
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ed Lance
Top achievements
Rank 1
Share this question
or