Solved

Gridview get all records across pages

Posted on 2010-08-16
5
726 Views
Last Modified: 2012-05-10
Hi,

I have a data centric application with 1000s of records. I have a gridview retrieving data via an object data source with a page size of 500. There are times when a user wants to access all records across all gridview pages. I made a checkbox in gridview with a default checked, whenever user wants to carry out operations on multiple records (export to excel, add note etc) they just check all rows and perform action. What I realised recently however was that these operations don’t work across gridview pages. My code is as follows:

for (int i = 0; i < gvContacts.Rows.Count; i++)
            {

                CheckBox cbSelectAll = (CheckBox)gvContacts.Rows[i].FindControl("cbSelectAll");

                if (cbSelectAll.Checked)
                {
				//do some action if checked
			}

		}		

Open in new window

So the problem is not to access all records of gridview, the problem is to access all records checked across pages. How could I solve it? Please help.

Thanks.
0
Comment
Question by:oldtedt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 12

Assisted Solution

by:HugoHiasl
HugoHiasl earned 62 total points
ID: 33444094
The advantage of using a paged datasource is that the other data will not be retrieved. The disadvantage is the same :-)

You have only the data for the visible 500 datarows available. If you need to execute operations on all datarows you need to retrieve the id's in the codebehind and store it in a hidden field or directly as javascript variable. If the "check all" is selected the operation needs to use this variable.

But be careful because this can lead to a poor performance if there are to much datarows.
0
 

Author Comment

by:oldtedt
ID: 33444153
isnt there a better way of achieving this?

I am trying to make the paging property of grindview false then bind the data, but problem with this method is the minute i bind data I lose all checked rows and since default is checked they all get checked.

0
 
LVL 16

Expert Comment

by:Kamal Khaleefa
ID: 33444399
there is another method by storing all your data in a session and then bind the session to the grid view
now on each post back save/ update the session with the current values of the grid and the re bind

so by this u keep all the checks in the session
0
 
LVL 12

Accepted Solution

by:
Ramkisan Jagtap earned 63 total points
ID: 33444936
There is also an another way to do it, By storing the selected values of each page into a hidden field. and using them whenever you want.

Regards,
Ram
0
 

Author Comment

by:oldtedt
ID: 33452573
Thanks for all your replies.
There is no straight forward way of achieving this as I was hoping. Even gmail select all button selects all on a page.
Session data was the way I was previously handled this entire grid, but the data is massive anywhere between 500 - 6000 records so I had to remove session variables. All the ways make the performance slower due to data size.

The way I have now tackled this problem is by having different buttons for each action eg.: export all and export selected. 'add note to selected' and 'add note to all'. there is no better way of solving this.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question