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

[Solved] how to find out if grid is in edit/ insert mode on save

6 Answers 1098 Views
Grid
This is a migrated thread and some comments may be shown as answers.
newbie
Top achievements
Rank 1
newbie asked on 27 May 2008, 06:44 PM
I have a Save button on my form.
On click of the save button i want to determine if the grid is in edit/insert mode (that is the row is not updated and grid is still open in edit/insert)

I am able to determine that is the grid has some rows however if it is the first row to be inserted I am unable to get the value.
I am doing something like this :

protected bool IsGridInEditInsertMode(RadGrid grid)
{
    if (grid.Items.Count > 0) // The grid has items
    {
        foreach (GridItem item in grid.Items)
        {
            if (item.IsInEditMode || item.OwnerTableView.IsItemInserted)
            {
                DisplayPopupMessage(name +
" is currently in edit mode. Please update or cancel before saving.");
                return true;
            }
            if (!item.HasChildItems)
            {
                if (item.Edit == true || item.IsInEditMode || item.OwnerTableView.IsItemInserted)
                {
                    DisplayPopupMessage(name +
" is currently in edit mode. Please update or cancel before saving.");
                    return true;
                }
            }
        }
// end foreach for gridItems.Count
    }
    else // the first record is inserted in the grid
    {
     }
}

Please help me achieve this.

6 Answers, 1 is accepted

Sort by
0
newbie
Top achievements
Rank 1
answered on 27 May 2008, 07:32 PM
I am checking for grid.MasterTableView.IsItemInserted
Is that the right approach?
0
Princy
Top achievements
Rank 2
answered on 28 May 2008, 06:34 AM

Hi Newbie,

Try the following code snippet.

CS:

  protected void Button1_Click(object sender, EventArgs e)  
    {  
        foreach (GridEditFormItem item in RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem) )  
        {  
            if (item.IsInEditMode)  
            {   
              //..
            }  
        }  
   } 

Thanks
Princy.
0
newbie
Top achievements
Rank 1
answered on 05 Jun 2008, 08:10 PM
That does not work for Insert.
Moreover now I want to find out if the detail Table is in insert mode when there are no records in the grid.
(That is there is no record in the detail table and the user has added one but not clicked the insert button yet and he is trying to save the form)
0
Sebastian
Telerik team
answered on 06 Jun 2008, 05:26 AM
Hi newbie,

How to determine the edit/insert mode and the level in the hierarchy inside the ItemCreated/ItemDataBound handlers of RadGrid you can learn from the following articles in the online documentation:

http://www.telerik.com/help/aspnet-ajax/grddistinguisheditinsertmodeonitemcreateditemdatabound.html
http://www.telerik.com/help/aspnet-ajax/grddistinguishgridrowsinhierarchyonitemdatabound.html

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Shinu
Top achievements
Rank 2
answered on 06 Jun 2008, 08:55 AM
Hi,

You can also try the following code snippet.

CS:
protected void Button1_Click(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.Items) 
        { 
           //Set the Name property for the Detail table 
            if ((item.OwnerTableView.Name == "Detail") && (item.OwnerTableView.IsItemInserted)) 
            {  
             
            } 
        } 
    } 


Thanks
Shinu.
0
newbie
Top achievements
Rank 1
answered on 06 Jun 2008, 04:39 PM
Thanks.

I did this and it is working for the details tables

foreach

(GridTableView nestedView in (grid.MasterTableView.Items[0] as GridDataItem).ChildItem.NestedTableViews)

{

if (nestedView.IsItemInserted)

{

DisplayPopupMessage(name +

" is currently in insert mode. Please insert or cancel before saving.");

return true;

}

}

Tags
Grid
Asked by
newbie
Top achievements
Rank 1
Answers by
newbie
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Sebastian
Telerik team
Shinu
Top achievements
Rank 2
Share this question
or