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

[Solved] Keep in Edit View on Update/Insert

2 Answers 122 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike Sweet
Top achievements
Rank 1
Mike Sweet asked on 02 Apr 2008, 04:33 PM

Hello,

I have a Grid whose editmode="forms".  I am doing some server-side validation on the item Insert and Update events.  I am not using a "DataSource", but instead binding directly to a collection of objects.  What I am having trouble with is that if the inserted/updated item is not valid, I want to keep that row in edit view.  My code for the Update event is as follows:

   void OnPartAliasesUpdateCommand(object source, GridCommandEventArgs e)  
   {  
      GridEditableItem item = e.Item as GridEditableItem;  
      string partCode = item.OwnerTableView.DataKeyValues[item.ItemIndex]["PartAlias"].ToString();  
      App.Core.BusinessObjects.Part partAlias = PartAliases[partCode];  
      RetrievePartAliasForm(item, partAlias);   
      if (!ValidatePartAliasForm(partAlias))  
      {  
         ccPartAliasStatusLabel.AddErrors(base.Rules);  
         return;  
 
      }  
      PartAliases[partAlias.PartAlias] = partAlias;  
      rdgPartAliases.Rebind();  
   } 

In other words, if the call to ValidatePartAliasForm return false, keep the item in edit view.  Any help would be appreciated. 

Thanks!

2 Answers, 1 is accepted

Sort by
0
Accepted
Ves
Telerik team
answered on 03 Apr 2008, 10:47 AM
Hello Mike,

RadGrid will be rebound automatically on update, so in case of failing validation, you should cancel it. That is -- set e.Canceled = true; before return; line. Also, due to the automatic databinding, you can remove the call to Rebind.

Hope this helps.

Best wishes,
Ves
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mike Sweet
Top achievements
Rank 1
answered on 04 Apr 2008, 03:36 PM
Thanks!  That did the trick.
Tags
Grid
Asked by
Mike Sweet
Top achievements
Rank 1
Answers by
Ves
Telerik team
Mike Sweet
Top achievements
Rank 1
Share this question
or