I have a RadGrid that allows automatic insert and update attached to an ObjectDataSource (ODS). During the ODS insert method I run validation checks and throw custom exceptions. I catch this in my RadGrid ItemInserted event and set the KeepInInsertMode to true and set the ExceptionHandled to true. When the page finishes loading the Insert Row is still there but the values in the edit fields (textboxes, dropdowns, etc) are no longer populated.
Is there a way to keep the values that the user entered before they saved? I need this for Update operations too.
public void RadGrid_Saved(object sender, GridInsertedEventArgs e) |
{ |
if (e.Exception != null) |
{ |
e.KeepInInsertMode = true; |
if (e.Exception.InnerException is ORMEntityValidationException) |
e.ExceptionHandled = true; |
} |
} |
That is how I catch my custom exception to keep the insert mode open.
Thanks!
6 Answers, 1 is accepted
The edntered values should stay as the user entered them in the edit form if you set:
e.KeepInEditMode = true;
e.ExceptionHandled = true;
And for the insert form, you can get the user input in the ItemInserted event and re-assign the values for to the edit form controls. Check the attached sample on how to achieve it.
All the best,
Iana
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.

I got it working already using a similar way but without having to reassign each value specifically. Since I'm using an ObjectDataSource I just kept a NonSerialized copy of the DataItem and re-inserted into the grid as a new insert item
public void RadGrid_ItemInserted(object sender, GridInsertedEventArgs e) |
{ |
if (e.Exception != null) |
{ |
e.KeepInInsertMode = true; |
RadGrid.MasterTableView.InsertItem(InsertEntity); |
if (e.Exception.InnerException is ORMEntityValidationException) |
e.ExceptionHandled = true; |
} |
} |
Looks like it's working fine now.
Thanks again.

Is there a way to keep the values that the user entered before they saved? I need this for Update operations too.
in the above example
RadGrid.MasterTableView.InsertItem(); what we need to pass in these insertItem function
Actually if you have set ExceptionHandled and KeepInInsertMode to true in the OnItemInserted event handler (as demonstrated below) you should be able to automatically persist the values.
protected
void
RadGrid1_ItemInserted(
object
source, GridInsertedEventArgs e)
{
if
(e.Exception !=
null
)
{
e.ExceptionHandled =
true
;
e.KeepInInsertMode =
true
;
DisplayMessage(e.Exception.Message);
}
else
{
DisplayMessage(
"Item inserted"
);
}
}
As for extracting the values from the insert item you can subscribe to the OnIsertCommand event and execute the below shown logic.
protected
void
RadGrid1_InsertCommand(
object
source, GridCommandEventArgs e)
{
GridEditFormInsertItem insertItem = e.Item
as
GridEditFormInsertItem;
Hashtable userValues =
new
Hashtable();
insertItem.ExtractValues(userValues);
}
Regards,
Angel Petrov
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Hi,
This is my code.
im struggle to persist the edited values in combo box for the first time.
Protected Sub RadGrid_ItemInserted(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridInsertedEventArgs) Handles RadGrid.ItemInserted
Dim edititem As GridEditableItem = TryCast(e.Item, GridEditableItem)
Dim RadComboBox As RadComboBox = TryCast(edititem.FindControl("RadComboBox"), RadComboBox)
If e.Exception IsNot Nothing Then
If e.Exception.InnerException.Message.Contains("ORA-00001") Then
e.ExceptionHandled = True
e.KeepInInsertMode = True
lblErrMsg.Text = "Already assigned."
End If
Else
e.Item.Expanded = True
End If
End Sub
I am sorry to say but the information provided is not sufficient for us to determine why are the values from the editors lost(respectively from the RadComboBox). Please share with us the entire markup and code-behind of the page so we could further investigate the matter.
Regards,
Angel Petrov
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.