Solved

Gridview get all records across pages

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

23 Experts available now in Live!

Get 1:1 Help Now