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

RadGrid custom paging with NeedDataSource issues

9 Answers 426 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jayesh
Top achievements
Rank 1
jayesh asked on 25 Apr 2011, 11:47 PM
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;
 
      }

9 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 29 Apr 2011, 08:29 AM
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.

0
jayesh
Top achievements
Rank 1
answered on 29 Apr 2011, 08:34 AM
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.
0
Mira
Telerik team
answered on 04 May 2011, 09:47 AM
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.

0
Robert
Top achievements
Rank 1
answered on 07 Dec 2011, 12:19 AM
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.


0
Lorenzo
Top achievements
Rank 1
answered on 22 Jan 2012, 11:32 PM
You are just great ! I was wondering if I was nuts o what !

Thank you

Lorenzo
0
John Adkins
Top achievements
Rank 1
answered on 12 Dec 2012, 03:20 PM
Thanks, you saved me sometime.
0
Mark Kucera
Top achievements
Rank 1
answered on 25 Mar 2013, 03:27 PM
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
0
Tonino
Top achievements
Rank 1
answered on 21 Jun 2013, 08:26 AM
Hello!

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

Regards,
Tonino.
0
Pavlina
Telerik team
answered on 26 Jun 2013, 12:34 PM
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.
Tags
Grid
Asked by
jayesh
Top achievements
Rank 1
Answers by
Mira
Telerik team
jayesh
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Lorenzo
Top achievements
Rank 1
John Adkins
Top achievements
Rank 1
Mark Kucera
Top achievements
Rank 1
Tonino
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or