RadGrid custom paging with NeedDataSource issues

10 posts, 0 answers
  1. jayesh
    jayesh avatar
    2 posts
    Member since:
    Jul 2007

    Posted 25 Apr 2011 Link to this post

    I have used custom paging using NeedDataSource but i see a very strange behavior of my RadGrid. I have about 800 records and i am displaying 10 records per page. Also, there is a search mechanism at the top using that user can search records ( i am not using internal filters). Everything works fine. I am taking my search parameters in my radgvRecords_NeedDataSource function and its being passed properly with RowIndexNum and MaximumRows parameters which handles paging. 

    I see first 10 records on page 1. When i click page 2, i just see 1 record. I checked my stored proc. It is returning 11 records when i pass RowIndexNum =10 and MaximumRows =10. So data is coming perfectly from database but RadGrid only displays the last row from this result set. I see data going through my BAL to my ASPX.CS page. The other strange part is when i hit page 3,4,5,6,7,... i see data properly without any problem. Its just on page 2.  I am pasting my bidding code here.

     
    protected void radgvRecords_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
          {
              // get search paramters
              string fname = txtPatientFName.Text.Trim();
              string lname = txtPatientLName.Text.Trim();
              string sDate = txtStartDate.Text.Trim();
              string eDate = txtEndDate.Text.Trim();
              string email = txtEmail.Text.Trim();
              int docid = Int32.Parse(ddlDoctors.SelectedValue.ToString());
              int clinicId = Int32.Parse(Session["cid"].ToString());
              bool status = false;
              // balance search parameters
              if (sDate.Trim() == null || sDate.Equals(""))
              {
                  sDate = System.Data.SqlTypes.SqlDateTime.MinValue.Value.ToShortDateString();
              }
              if (eDate.Trim() == null || eDate.Equals(""))
              {
                  eDate = DateTime.Now.ToShortDateString();
              }
              objFactory fac = new objFactory();
              IPrescription objPres = fac.getPrescriptionObject();
              VirtualItemCount = objPres.getTotalCountForSearchResult(sDate, eDate, fname, lname, docid, email, clinicId);
              radgvRecords.MasterTableView.VirtualItemCount = VirtualItemCount;
              radgvRecords.VirtualItemCount = VirtualItemCount ;
        
              int startRowIndex   = ((ShouldApplySortFilterOrGroup())? 0 : radgvRecords.CurrentPageIndex * radgvRecords.PageSize);
              int maximumRows = ((ShouldApplySortFilterOrGroup())? VirtualItemCount: radgvRecords.PageSize) ;
        
            
              List<IPrescription> pList = objPres.searchPrescriptionCustomPaging(sDate, eDate, fname, lname, docid, email, clinicId, startRowIndex, maximumRows);
              radgvRecords.DataSource = pList;
     
          }
  2. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 29 Apr 2011 Link to this post

    Hello Jayesh,

    Please make sure that you set the VirtualItemCount property of the MasterTableView to the corresponding number of records.
    Also, your stored procedure should return 10 records when you pass RowIndexNum =10 and MaximumRows =10.
    You can take a look at the Custom Paging demo to see how custom paging, grouping and filtering using NeedDataSource can be implemented.

    I hope this helps.

    Regards,
    Mira
    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.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. jayesh
    jayesh avatar
    2 posts
    Member since:
    Jul 2007

    Posted 29 Apr 2011 Link to this post

    I tried doing that. The situation is wired here. When i apply sorting and go to page 2 i see 10 records properly but without sorting when i go to page 2 it just display one record. Database is sending 10 records i can see them in a List<T> kind of generic list object on ASPX.CS page but dont see on grid. 

    Please advice. This problem has kept hold on my release next week.
  5. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 04 May 2011 Link to this post

    Hello Jayesh,

    Could you please try performing the following check and let me know whether it helps:
    protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        //...
     
        RadGrid1.AllowCustomPaging = !ShouldApplySortFilterOrGroup();
     
        //...
    }
     
    public bool ShouldApplySortFilterOrGroup()
    {
        return RadGrid1.MasterTableView.FilterExpression != "" ||
            (RadGrid1.MasterTableView.GroupByExpressions.Count > 0 || isGrouping) ||
            RadGrid1.MasterTableView.SortExpressions.Count > 0;
    }

    Regards,
    Mira
    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.

  6. Robert
    Robert avatar
    1 posts
    Member since:
    Dec 2011

    Posted 06 Dec 2011 Link to this post

    I had this same problem and I just figured it out. In my query to draw my data I was using a row number like so:

    WHERE rn BETWEEN :startRowIndex AND :startRowIndex + :maximumRows


    The problem is that the startRowIndex starts at zero. So if your page size is 10, I was getting rows 0 to 10 for page one, which is still 10 rows because row zero does not exist. However, for page two it would return rows 10 - 20, which is in fact 11 rows. It would then place that extra 1 on the next page and return only the last row of page two. I changed my where clause to:

    WHERE rn BETWEEN :startRowIndex + 1 AND :startRowIndex + :maximumRows

    Now every page works perfect! Hope this helps someone else.


  7. Lorenzo
    Lorenzo avatar
    42 posts
    Member since:
    Jul 2009

    Posted 22 Jan 2012 Link to this post

    You are just great ! I was wondering if I was nuts o what !

    Thank you

    Lorenzo
  8. John Adkins
    John Adkins avatar
    4 posts
    Member since:
    Oct 2009

    Posted 12 Dec 2012 Link to this post

    Thanks, you saved me sometime.
  9. Mark Kucera
    Mark Kucera avatar
    84 posts
    Member since:
    Sep 2009

    Posted 25 Mar 2013 Link to this post

    I had the exact same issue, fixed by making sure the number of items loaded into the RadGrid Datasource matched the PageSize.  I had a looping error and it was off by 1, and that was my issue.

    -Mark
  10. Tonino
    Tonino avatar
    107 posts
    Member since:
    Nov 2007

    Posted 21 Jun 2013 Link to this post

    Hello!

    Can someone tell me where the variable isGrouping is used / set from the code snipped of Mira?

    Regards,
    Tonino.
  11. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 26 Jun 2013 Link to this post

    Hello Tonino,

    If you check the code behind of this online demo you will see where the boolean variable is used.

    Regards,
    Pavlina
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017