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

5 posts, 1 answers
  1. Anand Kesavan
    Anand Kesavan avatar
    7 posts
    Member since:
    May 2010

    Posted 11 Oct 2010 Link to this post

    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    

  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 12 Oct 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Hoon
    Hoon avatar
    7 posts
    Member since:
    Oct 2010

    Posted 16 Jan 2012 Link to this post

    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?

  5. Hoon
    Hoon avatar
    7 posts
    Member since:
    Oct 2010

    Posted 16 Jan 2012 Link to this post

    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~

  6. xis xix
    xis xix avatar
    8 posts
    Member since:
    May 2010

    Posted 27 Jan 2012 Link to this post

    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. 
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017