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

RadGrid.Items.count gives worng value on Allow pagging set to True with page size .

4 Answers 250 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anand Kesavan
Top achievements
Rank 1
Anand Kesavan asked on 12 Oct 2010, 01:36 AM
Hi,
      I have grid with the pagging settings . as below

<

 

telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" PageSize="10" AllowSorting="true" ......

I bounded this grid with custom data source  (from my business object) Which has god more than 10 rows.   for ex. 15 rows.

Now I can see the grid has pagging. and on the first page I can view 10 records and in the second page I can see 5 records.  

And in my page I have button "Read Grid Data". on this button click event I am trying to read all the 15 rows by using the foreach

ON BUTTON CLICK EVENT ....

 

 

foreach (GridDataItem item in RadGrid1.Items)

 

{
  .... my business calculation... 
 

 



But this RadGrid1.Items retirn only 10 rows. But I need all 15 rows. I don;t know whether this is Telerik control issue or the way I am trying to read each rows using foreach. 

Please help me on this issue.  

Thanks 
Anand    

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 12 Oct 2010, 07:05 AM
Hello Anand,

One option is you can temporarily disabling the paging, rebind the grid and retrieve all the items. After getting all the item, you can re-enable the paging for grid.

C#:
RadGrid1.AllowPaging = false;// disabling paging
RadGrid1.Rebind();
 foreach (GridDataItem item in RadGrid1.Items)
  {
   . . . . . .
  }
RadGrid1.AllowPaging = true;// re-enable paging
RadGrid1.Rebind();

Thanks,
Princy.
0
Hoon
Top achievements
Rank 1
answered on 17 Jan 2012, 01:02 AM
Hi!
Don't you have better idea for this issue?

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{    
        if (e.CommandName.Equals("UPDATE"))
        {
            GridDataItem item = (GridDataItem)e.Item;
            TableCell cell_data = item["DataValue1"];
            TextBox Textbox_Item = cell_data.FindControl("Textbox_Item") as TextBox;

            int dataid = 
              (int)RadGrid1.MasterTableView.Items[e.Item.DataSetIndex].GetDataKeyValue("DataID");

         }
}

I got "Out of Index " error on above bold line because the DataSetindex is 11(this item is on second page) but
the MasterTableView has only 10 items each page. Its default's items always point first page.

I dont know how to access specific row at the second page at the server side.

Anyone has better solution for access data of paged Radgrid?

0
Hoon
Top achievements
Rank 1
answered on 17 Jan 2012, 01:25 AM

Oops~

Actually MasterTableView points to current page.
So I could solve my own issue like below.

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)

     if (e.CommandName.Equals("UPDATE"))
     {
         GridDataItem item = (GridDataItem)e.Item;
         TableCell cell_data = item["DataValue1"];
         TextBox Textbox_Item = cell_data.FindControl("Textbox_Item") as TextBox;

         int dataid = 
         (int)RadGrid1.MasterTableView.Items[(e.Item.DataSetIndex % RadGrid1.PageSize)].GetDataKeyValue("DataID");

     }
}

Sorry for stupid question.

Thanks~

0
xis xix
Top achievements
Rank 1
answered on 27 Jan 2012, 04:07 PM
Sorry bring this back from the death  but is this the only solution? 

RadGrid1.AllowPaging = false;// disabling paging
RadGrid1.Rebind();

.... 

RadGrid1.AllowPaging = true;// disabling paging
RadGrid1.Rebind();


i couldn find any other but this method seems somehow a little akward. 
Tags
Grid
Asked by
Anand Kesavan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Hoon
Top achievements
Rank 1
xis xix
Top achievements
Rank 1
Share this question
or