|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Where in the viewstate is a GridView's rows?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. 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. 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. 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) ) 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 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. >
Any hints on how to do frames in ASP.Net 2.0?
How to deselect item on single select listbox? Remove Dynamic User Controls from a collection Custom Treenodes in Treeview link on an entire row in a datagrid Would like to get two items from a dropdownlist control exposing collection. Gridview - Accessing a field value in current row DropDownList VS TextBox Customizing a TreeNode's viewstate |
|||||||||||||||||||||||