GridView, converting to object

  • Thread starter Thread starter Doogie
  • Start date Start date
D

Doogie

Hi
I have a gridview on my web page and I bind it to an object of my own
creation. When I click a button on that page, I want to get the data
from that gridview and cast it back into that object I created and
start to do work on it. I tried something like this:

List<MyObject> myObject = (List<MyObject>)myGrid.DataSource;


But I noticed that when I get to this line, "myGrid.DataSource" is
null. Yet, I can access the "myGrid.Rows.Count" value and see the
correct number of rows in my grid.


How can I convert to my own object?
 
I'm afraid your original data source is gone after postback. The grid
serializes its data in ViewState by default so you don't necessarily have to
rebind after every postback, so that gives the illusion that your original
data source is still there - but it's not.
If you want your original data source object then you'll have to manually
store it between postbacks or requery your data source after the postback.
 
I'm afraid your original data source is gone after postback.
I hope this helps,

Well, it helps but it's not what I was looking for. :) So I'm
assuming my best option is to store the data in a Session object and
then pull it out when needed?
 
yes. also you should turn off view state on the grid and re-databind on
postback.

-- bruce (sqlwork.com)
 
Back
Top