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

data access layer throws exception then edit form stayes in edit mode but populates the edit form controls with old values

3 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Imran Khalid
Top achievements
Rank 1
Imran Khalid asked on 12 May 2009, 08:59 PM
I have radgrid that calles the objectdatasource which calls the data access (DA) to populate the radgrid.
Radgrid has edit form template to update and insert the records.

1.  radgrid is open in edit form ..
2. User enters the NEW values and click the update button.
3. DA is called to update the database.
4. DA throws the exception that business logic rejected the update process ...
5. DA is automatically called to get the data again and  keeps the radgrid in edit mode...  and controls are populated with the original values this results in loss of NEW values entered by the user...

My understanding is that after step 4...  DA should not be called again to populate the edit form with original values.. Rather it should retain the NEW values and give the user a chance to modify these to try again the update process....



My code radgrid1_ItemUpdated is keeping the radgrid open in edit form template but the NEW values are lost as radgrid goes back to the DA to get the original data.  Where as this round trip to database is USELESS...

 

protected void radgrid1_ItemUpdated(object source, GridUpdatedEventArgs e)

 

{

 

if (e.Exception != null)

 

{

e.KeepInEditMode =

true;

 

e.ExceptionHandled =

true;

 


WHY radgrid goes to step 5.. How can i stop it... 

3 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 15 May 2009, 10:10 AM
Hello Imran,

I have answered to your question in the thread opened on this matter. Here is a quote of the answer:

Thank you for getting back to us and for the clarification.

Unfortunately the functionality you request is not attainable. By design the RadGrid will rebind itself if
ItemUpdated event is raised. Actually this behavior is not altered ( I have tested with Q2 2008 and previous versions) and the information in the suggested forum thread is misleading. For further information about grid event sequence refer to this online help article.

The difference between
GridView and the RadGrid is that the GridView does not have automatic rebind functionality. Hence it must recreate itself always from the viewstate. To avoid this behavior you can save the new values submitted to the server in the ViewState and then repopulate the edit from in the ItemDataBound event handler. Here is a code snippet showing what I mean:

[C#]:
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
        { 
            if (ViewState["newValues"] != null)  
            { 
                var newValues = (Dictionary<objectobject>)ViewState["newValues"]; 
                ViewState.Remove("newValues"); 
 
                GridTextBoxColumnEditor textBoxEditor = (e.Item as GridEditableItem).EditManager.GetColumnEditor("StubName"as GridTextBoxColumnEditor; 
                textBoxEditor.TextBoxControl.Text = newValues["StubName"].ToString(); 
 
                textBoxEditor = (e.Item as GridEditableItem).EditManager.GetColumnEditor("StubSummary"as GridTextBoxColumnEditor; 
                textBoxEditor.TextBoxControl.Text = newValues["StubSummary"].ToString(); 
            } 
        } 
    } 
 
    protected void RadGrid1_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e) 
    { 
        if (e.Exception != null
        { 
            e.ExceptionHandled = true
            e.KeepInEditMode = true
            IDictionary newValues = new Dictionary<objectobject>(); 
            e.Item.ExtractValues(newValues); 
            ViewState["newValues"] = newValues; 
        } 
    } 

Let me know if I can assist you further.


Best 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
Augusto
Top achievements
Rank 1
answered on 01 Dec 2011, 01:18 PM
Hello.

Is there any change in the Grid behavior regarding the handling of user entered values. I'm using version 2011.2.915.

Thanks
Augusto
0
Daniel
Telerik team
answered on 06 Dec 2011, 12:11 PM
Hello Augusto,

Changing this behavior would result in breaking changes which we prefer not to introduce. Although our RadGrid is similar to the ASP.NET GridView in many ways, it is a different control and because of that it works in different way in some scenarios.
Thanks for your understanding.

Kind regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Imran Khalid
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Augusto
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or