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

Insert/Update grid when master record is updated

2 Answers 44 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stefan
Top achievements
Rank 1
Stefan asked on 11 Oct 2010, 01:02 PM

Hi,

I have a page which displays a master record and contains one or more grids which display child records. The grids use user controls for displaying the data in edit mode.

If a user saves the master record (by clicking a SAVE button) while one of the child grids is still in edit mode, I would like to save the child grids automatically, ie find out if they are in edit or insert mode, retrieve the control values from the usercontrol and call insert/update on the data model (after validation).

If the insert/update is triggered by an event (Button Click), it is handled as follows: 

  protected void RadGrid1_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)   
   {   
       
//Get the GridEditableItem of the RadGrid     
       
GridEditableItem editedItem = e.Item as GridEditableItem;  
....

What I would like to to when the master record is saved:

protected void btnSave_Click(.....)  //Save event of master record
{
...Save master record...

If (childGrid.IsInEditMode)
{
    GridEditableItem editedItem = childGrid.GetCurrentEditableItem();  //How can this be achieved
    ChildObject co = GetData(editableItem):

    if (editableItem.IsInInsertMode())  //How can this be achieved
    {
        datamodel.insert(co):
    }
    else
    {
        datamodel.update(co);
    }
}
}

Any help would be greatly appreciated.

Thanks,
Stefan

2 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 14 Oct 2010, 11:26 AM
Hello Stefan,

To verify whether a grid table view is currently in insert mode you can use the GridTableView.IsItemInserted property. To get the insert item itself just utilize the GetInsertItem() method of the GridTableView object. Here is how this could look in your case:
if (childGrid.MasterTableView.IsItemInserted)
{
     GridEditableItem insertItem = childGrid.MasterTableView.GetInsertItem();
     //do something with the item
}

To verify whether some grid items are in edit mode and get references to these items, I would suggest that you use the grid's EditItems property. For more information about this property please check the following help topic (the "Using the EditItems collection" section)

Edit forms

I hope this helps.

Regards,
Martin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Stefan
Top achievements
Rank 1
answered on 17 Oct 2010, 08:06 PM
That worked fine, thank you very much.
Tags
Grid
Asked by
Stefan
Top achievements
Rank 1
Answers by
Martin
Telerik team
Stefan
Top achievements
Rank 1
Share this question
or