views:

115

answers:

1

I have a GridView inside of a User Control populated from a List of IObject. I need to get the contents of this GridView so I can export the data to CSV. I was just passing the whole GridView to the procedure and looping through it to get the data I needed. I am using MVP though, and was told this was a bad approach.

I want to convert the GridView back to a List of IObject, and then pass it to the Presenter. Any suggestions besides doing it the brute force way (looping through all columns and rows).

+1  A: 

Sounds daft, but why don't you get the data the same way that you originally bind the GridView to?

I recently changed some code that was written the way you describe (I didn't write it)- it actually broke the application as the huge ViewState was too big for a postback (Maximum Request length exceeded)!

I merely extracted the data from the DB, cached it and then got the cached version for the export to CSV (it was actually export to Excel but that's beside the point).

Of course I turned the ViewState on the GridView off, as it was no longer needed.

RichardOD
My only concern with getting the Data again is that it is a Search page, and the user could change the search parameters, then click export and get something different than what was in the Grid ... but I think I may go that approach.
Martin
@Martin- just make sure the two are in sync- in the code I changed the grid also had search controls at the top. Good luck.
RichardOD