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

Rad Grid returns incorrect row/item count

1 Answer 270 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ratheesh
Top achievements
Rank 1
ratheesh asked on 02 Sep 2010, 08:03 AM
Hi ,

I have a rad grid and in item databound im trying to get the items count . My dataset contains 3 items and is also bound to the rad grid where its displayed . In Item Databound radGrid.Items.Count  returns 2 , where as it should be 3 .
Similarly i used radGrid.MasterTableView.Items.Count ,returns 2 .

What could be the problem

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 02 Sep 2010, 10:32 AM
Hello Ratheesh,


The ItemDataBound event is raised when a data item (represented by a GridItem object) is bound to data in the Telerik RadGrid control. That means it fires too early for binding all the rows in the grid. I believe looping through the items in PreRender would be an alternative.

in PreRender event.
protected void RadGrid1_PreRender(object sender, EventArgs e)
   {
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
        {
           // your code here
        }
   }

in the ItemDataBound event after binding all the dataitems:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridFooterItem)
    {
        int count = RadGrid1.MasterTableView.Items.Count;
    }
}


-Shinu.
Tags
Grid
Asked by
ratheesh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or