How to get total rows count of Radgrid

2 Answers 6041 Views
Grid
jeevitha
Top achievements
Rank 1
jeevitha asked on 01 Dec 2009, 06:09 AM
Hi i need to display the count of rows of the grid in the top of my page. I used the follg code. but it shows the count of that page alone. i want all the rows irrespective of the pages. and i also need to display the pages co9unt. pls help me
  protected void gridViewPograms_ItemDataBound(object sender, GridItemEventArgs e)
        {
            int i = gridViewPograms.Items.Count;
            labelCount.Text = i.ToString();
        }

Thanks,
Jeevitha

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 01 Dec 2009, 06:34 AM
Hello Jeevitha,

Try the following code in order to get the total number of items.

CS:
 
    protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        RadGrid1.MasterTableView.AllowPaging = false
        RadGrid1.Rebind(); 
        Label1.Text = RadGrid1.MasterTableView.Items.Count.ToString(); 
        RadGrid1.MasterTableView.AllowPaging = true
        RadGrid1.Rebind(); 
    } 

-Shinu.
Richard
Top achievements
Rank 1
commented on 11 Jul 2012, 06:36 PM

I'm joining the discussion a little late, but here goes:

On the server side I want to get the total number of rows/items in the grid without having to do an extra rebind. 

As it currently stands. <grid>.Items.Count and <grid>.MasterTableView.Items.Count both return the number of items in the current page, not the total for the grid.

Rich Sorensen
Shinu
Top achievements
Rank 2
commented on 12 Jul 2012, 02:50 AM

Hi Richard,

Please try the following code snippet to get the total count of items irrespective of paging.

C#:
protected void RadGrid1_ItemEvent(object sender, GridItemEventArgs e)
{
    if (e.EventInfo is GridInitializePagerItem)
    {
        int rowCount = (e.EventInfo as GridInitializePagerItem).PagingManager.DataSourceCount;
    }
}

Thanks,
Shinu.
Richard
Top achievements
Rank 1
commented on 12 Jul 2012, 03:10 PM

Thanks - the logic works. 

However, it would be nice to have a property on the grid control that could be accessed after a rebind operation rather then implementing more event code which would be called repeatedly.
Justin
Top achievements
Rank 1
commented on 28 Jul 2014, 10:05 PM

Try this:

int i = gridViewPograms.MasterTableView.VirtualItemCount
Mark
Top achievements
Rank 1
commented on 29 Jul 2014, 01:38 PM

Hi Justin,

That wont do im afraid, that will give you the limit of what you set your virtual count at
Allen
Top achievements
Rank 2
Iron
Veteran
commented on 13 Oct 2021, 11:22 AM

SO why can't you just set VirtualItemCount to the number of rows in the DataTable in Needs_DataSource ??? 

 It's just a statistic in this case.

Allen
Top achievements
Rank 2
Iron
Veteran
commented on 13 Oct 2021, 12:49 PM

and this seems to work for a grid with 20K rows...

 

0
Eyup
Telerik team
answered on 01 Aug 2014, 08:50 AM
Hi All,

You can also give this approach a try:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridPagerItem)
    {
        GridPagerItem pagerItem = e.Item as GridPagerItem;
        int itemsCount = pagerItem.Paging.DataSourceCount;
        Label1.Text = "Total items count: " + itemsCount;
    }
}

Hope this helps.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

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