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

Keep values in edit items after handling exception

6 Answers 185 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gilbert
Top achievements
Rank 1
Gilbert asked on 23 Apr 2010, 11:49 PM
Hi,

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

Sort by
0
Iana Tsolova
Telerik team
answered on 28 Apr 2010, 10:44 AM
Hello Gilbert,

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.
0
Gilbert
Top achievements
Rank 1
answered on 28 Apr 2010, 02:44 PM
Thanks Iana,

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.
0
Anandhi
Top achievements
Rank 1
answered on 30 May 2014, 09:20 AM
I have a RadGrid that allows automatic insert and update attached to an EntityDataSource (EDS). During the EDS 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.         


in the above example

 RadGrid.MasterTableView.InsertItem();    what we need to pass in these insertItem function




0
Angel Petrov
Telerik team
answered on 04 Jun 2014, 07:54 AM
Hi Anandhi,

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");
        }
    }
That said the behavior experienced is not expected and in order to investigate why does it occur I would like to ask you to provide us with the markup and code-behind of the page.

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);
    }
Once the ExtractValues method is called the userValues Hashtable will be populated with the data entered by the user.

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.

 
0
Anandhi
Top achievements
Rank 1
answered on 04 Jun 2014, 01:26 PM

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

 

0
Angel Petrov
Telerik team
answered on 09 Jun 2014, 01:18 PM
Hi Anandhi,

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.

 
Tags
Grid
Asked by
Gilbert
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Gilbert
Top achievements
Rank 1
Anandhi
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or