views:

1315

answers:

4

I'm using a Gridview to hold records that user can click on the checkbox in each record for indication that he/she want to save that record(after editing the data) and user can select as many records as they want and save them all at once.

In the code behind, I'll loop thour the gridview and look for the checkbox to save the record. If I disable the Gridview's view state. I can't loop it but if i enabled the gridview's viewstate then the gridview view state can go as high as 1mb and beyond.

what will be the best way to reduce the viewstate on this girdview control or is my approach is wrong?

A: 

if you disable gridview viewstate, you can't get gridview data on postback, if your data is heavy in gridview as you told, try to reducre number of records in gridview or edit these records one by one...

Muhammad Akhtar
+1  A: 

If you can't reduce the size of your viewstate you could try an alternate solution. You can store your viewstate on the server. This blog post shows how to implement this:

Reducing the page size by storing ViewState on Server

I've implemented something similar to this on a page that had a huge viewstate and it worked great. I would try to optimize the viewstate before moving to something like this since it is creating a bit of overhead.

I think I used this article (it's been a while) and had to modify it for SQL as this uses the filesystem: Persisting View State to the File System

Alex
A: 

I agree with Alex. You could also ues a temp table to hold the data. I used this scenario on a project and it works fine. You could also use caching, but again that's puting the load on the web server (unless you have some sort of distributed caching).

Saif Khan
+1  A: 

If you're open to the idea you might want to consider implementing custom paging to reduce the number of records returned. Perhaps start with the default paging but that returns all records. If you want better performance custom paging is the way to go.

Some helpful material:

  1. Efficiently Paging Through Large Amounts of Data

  2. GridView ObjectDataSource LINQ Paging and Sorting

  3. Improve GridView Performance by Delegating Paging to SQL Server

Ahmad Mageed