Home All Groups Group Topic Archive Search About

Where in the viewstate is a GridView's rows?

Author
3 Jan 2006 10:38 PM
Keith Patrick
I'm trying to track down a problem where a dynamic gridview I have is not
restoring its rows correctly.  Stepping into a derived GridView, I've found
that the GV *is* getting a viewstate passed to LoadViewState with the
correct # of rows specified.  However, I can't find where in the viewstate
(not on the datasource/datasourceview, either) the rows are being stored,
since the values are not being restored & I can't figure out how the items
are added back.

Author
4 Jan 2006 12:27 AM
Keith Patrick
I never found where it was stored (I assumed it was in the
datasourcecontrol, but I couldn't see the data there), but basically, the
gridview restores the rows from either databinding or by viewstate via
CreateChildControls(IEnumerable, bool databinding).  I was overriding
CreateChildControls() without calling base.CreateChildControls(), so this
method never got called, preventing my rows from being restored.
Author
4 Jan 2006 9:51 PM
Mike MacMillan
Keith,
  does the control have both SaveViewState and LoadViewState overridden
for custom handling?  if so, SaveViewState will tell you what's being
saved and how, that way during LoadViewState you can put everything
back where it belongs.  can you post some of the code perhaps?

  thanks,
  Mike MacMillan


Keith Patrick wrote:
Show quoteHide quote
> I never found where it was stored (I assumed it was in the
> datasourcecontrol, but I couldn't see the data there), but basically, the
> gridview restores the rows from either databinding or by viewstate via
> CreateChildControls(IEnumerable, bool databinding).  I was overriding
> CreateChildControls() without calling base.CreateChildControls(), so this
> method never got called, preventing my rows from being restored.
Author
5 Jan 2006 1:33 AM
Keith Patrick
I overrode them so I could see what the viewstates were, but I never changed
the viewstates in the gridview.  The problem was that I was breaking the
CreateChildControls() method chain, preventing the rows being restored from
an IEnumerable that something passes into the GV (the specific method I
needed called was CreateChildControls(IEnumerable data, Boolean
isDataBinding) )
Author
6 Jan 2006 9:59 AM
Teemu Keiski
It stores the count of rows when databinding, and on postback creates a
dummy data source (array, count from the count stored to ViewState) to
instantiate the rows back again. GridViewRows are controls themselves
(derive from TableRow), so basically when they are added back to the
GridView, they load their own state. So essentially what GridView handles
for this matter is to recreate the same count of GridViewRows.

The key points are PerformDataBinding and CreateChildControls methods, which
delegate row creation to overload of CreateChildControls taking the data
source as IEnumerable and a boolean flag to tell if databinding or restoring
from ViewState
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


Show quoteHide quote
"Keith Patrick" <richard_keith_patrick@nospam.hotmail.com> wrote in message
news:u6b$pZLEGHA.1424@TK2MSFTNGP12.phx.gbl...
> I'm trying to track down a problem where a dynamic gridview I have is not
> restoring its rows correctly.  Stepping into a derived GridView, I've
> found that the GV *is* getting a viewstate passed to LoadViewState with
> the correct # of rows specified.  However, I can't find where in the
> viewstate (not on the datasource/datasourceview, either) the rows are
> being stored, since the values are not being restored & I can't figure out
> how the items are added back.
>