Solved

Gridview get all records across pages

Posted on 2010-08-16
5
719 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
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now