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

[Solved] MasterEditTemplate remains visible after update

5 Answers 161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Reid
Top achievements
Rank 2
Reid asked on 04 Mar 2009, 05:28 PM
Hello,

I have a RadGrid that contains a MasterEditTemplate for editing records that is working fine (like the the other 4 RadGrids contained in this template), but for some reason it remains visible after the update.  

If I place the grid in edit mode using the custom <CommandTemplate> and then click the cancel link the template closes as it should.  Yet i when I place the grid in edit mode (clicking the AutoGeneratedEdit column icon) and update the database the template remains visible.  I can confirm that the "UpdateSponsoredLinkSponsor()" call returns true and is assigned to the e.Cancelled member of the GridCommandEventArgs parameter to the event.  In every other case on the web template this closes the MasterEditTemplate but not in this one.

protected void grdSponsoredLinkSponsor_ItemCommand(object source, GridCommandEventArgs e) 
    {     
 
        Controller controller = GlobalMethods.GetController(); 
        switch ( e.Item.OwnerTableView.Name ) 
        { 
            case "SponsoredLinkSponsor"
                { 
                    switch ( e.CommandName ) 
                    { 
                        case RadGrid.InitInsertCommandName: 
                            { 
                                .. 
                            } 
                        case RadGrid.PerformInsertCommandName: 
                            { 
                                .. 
                            } 
                        case RadGrid.EditCommandName: 
                            { 
                               .. 
                            } 
                        case RadGrid.UpdateCommandName: 
                            { 
                                Guid primaryKey = (Guid) e.Item.OwnerTableView.DataKeyValues[0]["PrimaryKey"]; 
                                SponsoredLinkSponsor activeSponsoredLinkSponsor = (SponsoredLinkSponsor) controller.DataCache.GetObject(primaryKey);                                 
 
                                e.Canceled = !UpdateSponsoredLinkSponsor(activeSponsoredLinkSponsor); 
                                if ( e.Canceled == false ) 
                                {                                     
                                    ... 
                                    grdSponsoredLinkSponsor.Rebind(); 
                                } 
                                break; 
                            } 
                    break; 
                } 
        } 
     


I have placed a copy of the .aspx and .cs files on my server in a public folder here:

Can anyone tell me what might be going on here?  Again the update method returns true.

Thanks


5 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 09 Mar 2009, 12:23 PM
Hello Reid,

You can try to clear all items which are in edit mode with the following code:
case RadGrid.UpdateCommandName:   
{   
   Guid primaryKey = (Guid) e.Item.OwnerTableView.DataKeyValues[0]["PrimaryKey"];   
                               SponsoredLinkSponsor activeSponsoredLinkSponsor = (SponsoredLinkSponsor) controller.DataCache.GetObject(primaryKey);                                   
   
   e.Canceled = !UpdateSponsoredLinkSponsor(activeSponsoredLinkSponsor);   
   if ( e.Canceled == false )   
   {                                       
       ...   
       grdSponsoredLinkSponsor.MasterTableView.ClearEditItems();  
       grdSponsoredLinkSponsor.Rebind();   
   }   
   break;   
}   


The other approach is to clear the EditItems collection if the EditMode is the "InPlace", or the EditFormItem collection if the EditMode is in "EditForms" or "PopUp".

In your case this code snippet should do the trick:
case RadGrid.UpdateCommandName:   
{   
   Guid primaryKey = (Guid) e.Item.OwnerTableView.DataKeyValues[0]["PrimaryKey"];   
                               SponsoredLinkSponsor activeSponsoredLinkSponsor = (SponsoredLinkSponsor) controller.DataCache.GetObject(primaryKey);                                   
   
   e.Canceled = !UpdateSponsoredLinkSponsor(activeSponsoredLinkSponsor);   
   if ( e.Canceled == false )   
   {                                       
       ...   
       grdSponsoredLinkSponsor.MasterTableView.EditItems.Clear();  
       grdSponsoredLinkSponsor.Rebind();   
   }   
   break;   
}   

For further information you can refer to this online help article.

Kind regards,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Reid
Top achievements
Rank 2
answered on 09 Mar 2009, 02:10 PM
Hello Georgi,

Since the time I posted this until you repsonded I actually added the line as you mentioned and it does not work.  The edit template remains visible.

I can say that if I add a button on the template with a CommandArgument value of "PerformInsert" (or Update) and a CommandName value of "PerformInsert" (or Update) it works fine.  But if I use the "Save Action" button in the CommandTemplate it does not.

This is happening on all the RadGrids on the template (5 of them).
0
Accepted
Georgi Krustev
Telerik team
answered on 12 Mar 2009, 07:25 AM
Hi Reid,

To attain the functionality you are searching for you need to use the following code:
    protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
    { 
 
        switch (e.CommandName) 
        { 
            case RadGrid.UpdateCommandName: 
                { 
                    //TODO: Perform update of the rows here. 
                    RadGrid1.MasterTableView.ClearEditItems(); 
                    break
                } 
            case RadGrid.PerformInsertCommandName: 
                { 
                    if(e.Item.OwnerTableView.IsItemInserted) 
                        e.Item.OwnerTableView.IsItemInserted = false
 
                    break
                } 
        } 
    } 

For your convenience I have attached a test project which implements this functionality to this support ticket.

All the best,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Reid
Top achievements
Rank 2
answered on 12 Mar 2009, 01:58 PM
That solved it!  Thank you Georgi!
0
Quantesys IT
Top achievements
Rank 1
answered on 15 Jul 2009, 11:52 AM
I had the same problem and I solve it with the solution you provided:
RadGrid1.MasterTableView.ClearEditItems(); 

Thank you for your help !
Tags
Grid
Asked by
Reid
Top achievements
Rank 2
Answers by
Georgi Krustev
Telerik team
Reid
Top achievements
Rank 2
Quantesys IT
Top achievements
Rank 1
Share this question
or