Failed to load viewstate on editable datagrid

S

steve gibson

I am trying to add a new row to the header of an edittable
datagrid.

I have achieved this by adding a row using:

DataGrid1.Controls[0].Controls.AddAt(0, dgItemHeader);

in the ItemDataBound

This work fine, but when I do a postback I get:

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.

I attempt to call the DataGrid1.Controls[0].Controls.AddAt
(0, dgItemHeader); in the Page.Init

but get the followingstack trace:

[ArgumentOutOfRangeException: Specified argument was out
of the range of valid values. Parameter name: index]
System.Web.UI.ControlCollection.get_Item(Int32 index)
WebApplication1.PubGrid.AddHeader() in
c:\dev\ocitoemea\emeaweb\webapplication1
\pubgrid.aspx.cs:124
WebApplication1.PubGrid.OnInit(EventArgs e) in
c:\dev\ocitoemea\emeaweb\webapplication1
\pubgrid.aspx.cs:387
System.Web.UI.Control.InitRecursive(Control
namingContainer)
System.Web.UI.Page.ProcessRequestMain()


Switching ViewState off for the elements I have added has
no effect.

I am unable to setview off for the Grid as this prevents
the grid from being edittable.

Any Ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top