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

Closing a ascx control inside a RadGrid

1 Answer 230 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 14 Dec 2016, 03:16 PM
I am trying to do an insert in editForm in a RadGrid nested in another RadGrid's editform.  I need a way to tell the parent grid to close its editForm.



I have a RadGrid (RadGridMain) that lets the user display and edit some data.  It works fine for update and delete.

In order to do inserts and updates using slightly different processes, I have an Edit.ascx and an Insert.ascx.  The OnItemCommand adjusts the user control appropriately like:

01.protected void RadGridMain_OnItemCommand(object sender, GridCommandEventArgs e)
02.{
03.    if (e.CommandName == RadGrid.InitInsertCommandName)
04.    {
05.        RadGridMain.MasterTableView.EditFormSettings.UserControlName = "~/Insert.ascx"
06. 
07.        // Set up the control
08.        Control control = Page.LoadControl("~/Insert.ascx");
09.        RadGrid radGridInsert = control.FindControl("radGridInsert") as RadGrid;
10. 
11.        radGridInsert.NeedDataSource += RadGridInsertSelector_OnNeedDataSource;
12. 
13.        // give the child a handle to the parent
14.        PSC.Controls.UdcsConnectionInsert.ParentRadGrid = RadGridMain;
15.    }
16.    else if (e.CommandName == RadGrid.EditCommandName)
17.    {
18.        RadGridMain.MasterTableView.EditFormSettings.UserControlName = "~/Edit.ascx";
19.    }
20.}


The reason that I am loading the insert control and assigning the NeedDataSource is that I am doing this in SharePoint, and this seems to be the best way.


So, the insert.ascx control gives the user a RadGrid (let's call it radGridInsert) to select an item to associate with and then opens up an editform in radGridInsert to do the insert.  Once the insert is done, they click Save and the RadGridInsertSelector editform closes.  This works great.

The catch is that when they save or cancel in the radGridInsert editForm, I want to tell the outer RadGrid (RadGridMain) to stop editing and close its editform.  The only way that I have been able to do it so far is by having a button that calls the cancel command in the ascx outside the RadGridInsertSelector.

In the radGridInsert_OnInsertCommand, I can save the data and close the radGridInsert editform, but I need a way to pass this to the parent so that it closes its editform.

In radGridInsert_OnInsertCommand, I have tried calling
ParentRadGrid.MasterTableView.IsItemInserted = false;


and

GridEditFormItem editFormItem = e.Item as GridEditFormItem;
GridDataItem parentItem = editFormItem.ParentItem;
parentItem.EditFormItem.Edit = false;


Any suggestions would be greatly appreciated.

Thanks

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 19 Dec 2016, 11:39 AM
Hi Mark,

In order to force the RadGrid to close its edit form you can use the approach suggested in the thread below. You should get reference of the parent grid, close the edit form and rebind the grid.


With that said, have in mind that adding handler for NeedDataSource late in the page ligecycle can result in unexpected behavior. Please consider using the Page_Init/Page_Load event to attach handler for NeedDataSource.


Regards,
Viktor Tachev
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or