This is a migrated thread and some comments may be shown as answers.

How do i get the Total Grid Item Count when Paging is enabled?

5 Answers 881 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ullas
Top achievements
Rank 1
Ullas asked on 16 Jun 2011, 12:32 AM
Hi,
I am trying to get the total items count on my grid (total count of all the items in all the pages of the grid) in my code behind when Paging is enabled.
 
My data source for the grid returns 17 rows and the data is displayed in 2 pages. 
When i do an Items count it only returns me 10 (since my page size is 10)
i tried this code which was suggested in this forum -

 

<telerik:RadGrid ID="GridInvoiceDetailsPO" runat="server" AllowPaging="True"
AutoGenerateColumns="False" PageSize="10" Visible="True" Skin="Outlook"
PagerStyle-Mode="NextPrevAndNumeric" PagerStyle-AlwaysVisible="true"

.... />


int
i = GridInvoiceDetailsPO.Items.Count;
GridInvoiceDetailsPO.AllowPaging = false;
GridInvoiceDetailsPO.Rebind();
int j = GridInvoiceDetailsPO.Items.Count;
GridInvoiceDetailsPO.AllowPaging = true;
GridInvoiceDetailsPO.Rebind();
int k = GridInvoiceDetailsPO.Items.Count;

 

 

 

But i, j and k all return 10. is there something i am doing wrong?
Also i dont just want to get the total count, i want to iterate through the collection and get/set some data.

Ullas

 

 

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 Jun 2011, 06:09 AM
Hello Ullas,

Try the following code snippet.
C#:
protected void rad_ItemEvent(object sender, GridItemEventArgs e)
{
 if (e.EventInfo is GridInitializePagerItem)
        {
            int i=(e.EventInfo as GridInitializePagerItem).PagingManager.DataSourceCount;
        }
}

Thanks,
Shinu.
0
Ullas
Top achievements
Rank 1
answered on 16 Jun 2011, 06:12 AM
Thanks Shinu.
I can get the count that way. But i want to loop through the collection and access each and every item. how can i do that?

Ullas
0
Pavlina
Telerik team
answered on 16 Jun 2011, 11:27 AM
Hello Ullas,

When the grid is in paging mode only the items for the current page are retrieved - there are no items in memory. However, if you want to operate with all records from the source when the grid paging is enabled, reference directly the data from the underlying data source to process further operations over it.

All the best,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Ullas
Top achievements
Rank 1
answered on 16 Jun 2011, 10:35 PM
OK.
is there any way we can do this in JavaScript as well?

Ullas
0
Accepted
Pavlina
Telerik team
answered on 17 Jun 2011, 03:57 PM
Hi Ullas,

You can refer to the forum thread below for more information about how to achieve your goal:
http://www.telerik.com/community/forums/aspnet/grid/retrieving-all-grid-values-client-side.aspx

Regards,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Ullas
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ullas
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or