views:

98

answers:

3

Hi,

I'm running a number of CAML queries against a large list in SharePoint 2010, and displaying the results in a gridview to the end user. I wish to page through the results returned by the query to improve performance. However, I am required to display a total count of the items returned by the query on the paging control. My question is, how can I determine the total number of items that will be returned by each query without actually returning them all in a single SPListItemCollection? To be precise, I wish to page through the results 10 items at a time; how can I do this and still have a total count of all items returned by the query?

Update

So far, none of the answers given have addressed my question - as such, I'm offering a bounty. I need to be able to get a total count of the number of items that a CAML query will return without having to run the query and return all of the items. This will enable me to display this total count value to the end user (a set requirement), while paging through the items collection to display a specific page of results in a gridview. This would avoid a massive performance hit for large lists on the page containing the gridview first loading.

If no one offers a valid answer to the above, I will accept an answer that gives a link to an MSDN article that explicitly says that the above functionality cannot be implemented.

Thanks, MagicAndi.

+1  A: 

It is a SharePoint limitation. This is why SharePoint doesn't show how many pages you have in view.

cement
Cement, thanks, this is what I thought. Can you point me towards a MSDN reference for this?
MagicAndi
No feature - no MSDN reference :) Only forums http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/1ac0cd45-8ba2-439f-b534-bc05573ae33e
cement
+1  A: 

You can create a view for that list with items per page limited to say 10. Then use a listview control (instead of gridview) and bind the view.

sssreddy
sssreddy, thanks for your reply. Unfortunately, I have already looked at using the XSLTListViewWebPart to display the list, but I wasn't able to customize the control to display a total count. This is a set customer requirement.
MagicAndi
sssreddy, no, unfortunately not. In addition to displaying a set number of items per page, the customer requires that the total number of items in the current view of the list (including any filtering criteria being applied) is displayed in the pager control. It is not possible to update the list view control to include this total count of items in the view.
MagicAndi
If I understand right, you want a count of the number of items displayed per page. {SPList list = web.lists["TestList"]; SPViewCollection viewCollection = list.Views; stringCollection listofFieldstodisplay = new stringCollection; listofFieldtodisplay.Add("Field1"); viewCollection.Add("NamoftheNewView",listofFieldtodisplay,CAMLQUERY, 10,true,false;} .. Now on UI... { Microsoft.SharePoint.ListView myListView = null; myListView.ID = list.ID; myListView.view = list.views["nameofthenewview"]; mylistview.Databind(); } ..
sssreddy
As we mentioned 10 items and set pagination as true, it will always display only 10 items per page. Litview will automatically display the which set of 10 items it is displaying. Hope this solves your problem.
sssreddy
Also filtering, sorting are automaticallly handled
sssreddy