GridView, converting to object

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?
 
S

Steve C. Orr [MCSD, MVP, CSM, ASP Insider]

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.
 
D

Doogie

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?
 
B

bruce barker

yes. also you should turn off view state on the grid and re-databind on
postback.

-- bruce (sqlwork.com)
 

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,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top