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

Dynamic RadGrid Issues

0 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
blablabla
Top achievements
Rank 1
blablabla asked on 03 Oct 2011, 05:33 PM
Hi,

I'm having some issues with RadGrids created dynamically in the code behind. Here's an explanation of the situation:

I have a static RadGrid defined, let's call it "MainRadGrid", as well as a static formview below it. When I click on a row inside this radgrid, I fill out the formview with data depending on the row selected in the MainRadGrid. There's a RadAjaxPanel around these controls.

Some of the fields inside this formview are created dynamically. This includes several RadGrids that use their own ObjectDataSources with corresponding select, insert, and delete methods, as well as Automatic Inserts and Deletes enabled. Till now, everything is fine.

My page has an "Edit" button that puts the formview in edit mode. I click it, and everything goes into edit mode, including my dynamic radgrids (editmode = inplace, and all rows editable). All fine till now as well.

My issue occurs when I click on the "Add" button of the dynamic radgrids. At that point, I get an exception, which is the following:

Sys.WebForms.PageRequestManagerServerErrorException: Failed to load viewstate.  The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.  For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

---
More explanations:
I catch the RowClicked command in the MainRadGrid_ItemCommand event. At that point, I retrieve a couple of values from the selected row and store them in the page's viewstate and then bind the formview.
I need these values to be able to load the correct data and dynamic fields into the formview. From my understanding, this is too late because the viewstate has already been loaded, which causes my issue mentioned above.

Any help with this issue?

---

I tried disabling the viewstate for my FormView. This fixes the issue mentioned above, but causes another one. Basically, the InitInsert command works fine when  I click on the "Add" button, but when I input values in the row generated then click on insert, the RadAjaxPanel mentioned earlier does its thing and the new row that was supposed to be added disappears instead, and the ObjectDataSource insert method is never called. The dynamically added RadGrid also goes back into readonly mode and does not take into consideration the EditIndexes.

So that's another issue.

---
To summarize:
1. I have a MainRadGrid and a FormView. I select a row in the RadGrid and databind the formview.
2. The formview creates dynamic controls depending on the row selected, including dynamic RadGrids that are connected to their own ObjectDatasources. This is done in the FormView_ItemCreated event.
3. I go into edit mode, and then attempt to add a new row to the dynamic RadGrids, and I get a viewstate error. If I disable the viewstate, the added row is there but when i click insert, the row disappears and the grid is not in edit mode anymore.

This is long, I know, but i hope you got this far. I will attempt to post sample code if possible.

No answers yet. Maybe you can help?

Tags
Grid
Asked by
blablabla
Top achievements
Rank 1
Share this question
or