Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

GridView, converting to object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Doogie - 25 Jul 2007 15:19 GMT
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?
Steve C. Orr [MCSD, MVP, CSM, ASP Insider] - 25 Jul 2007 15:38 GMT
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.

Signature

I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net

> Hi
> I have a gridview on my web page and I bind it to an object of my own
[quoted text clipped - 9 lines]
>
> How can I convert to my own object?
Doogie - 25 Jul 2007 16:01 GMT
> 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?
bruce barker - 25 Jul 2007 16:21 GMT
yes. also you should turn off view state on the grid and re-databind on
postback.

-- bruce (sqlwork.com)

>> I'm afraid your original data source is gone after postback.  
>
[quoted text clipped - 3 lines]
> assuming my best option is to store the data in a Session object and
> then pull it out when needed?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.