Solved

Gridview get all records across pages

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

786 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