We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Paging from the database. Pass to grid the "total pages"

Thread ID:





98726 Mar 23,2011 12:40 AM UTC Mar 31,2011 01:00 PM UTC ASP.NET MVC (Classic) 3
Tags: Grid
Jose A Fernandez
Asked On March 23, 2011 12:40 AM UTC

In a current project we are using the Grid for ASP.NET MVC, we're paging with JSON.
We need paging in the database, request a particular page. At the moment my paging stored procedure, you map a PE function returns a collection of my entities, and a variable out the total number of pages
I can pass the grid as the total number of pages? how?
Then the grid can render the page numbers (the foot of the paged)

Eswari S [Syncfusion]
Replied On March 23, 2011 12:19 PM UTC

Hi Jose,

Thank you for your interest in Syncfusion products.

We have analyzed your query and found it difficult to understand the requirement. So can you please explain the requirement with some useful scenario, so that we can update you with more

appropriate solution.

However we can achieve the paging with JSON mode by calling the post action method in controller. Please refer the below code snippets.

public ActionResult Index( )
var data = new StudentDataContext().Student.ToList();
return View();

public ActionResult Index(PagingParams args)
var data = new StudentDataContext().Student.ToList();

return data.GridJSONActions(); // Returns data using GridJSONActions



.ActionMode(ActionMode.JSON) \\ here specify the action mode as JSON.

.Column(column => {
column.Add(p => p.UniversityCode).HeaderText("University Code");
column.Add(p => p.Title);


Please let us know if you need further assistance.


Jose A Fernandez
Replied On March 29, 2011 12:41 AM UTC

Thanks for replying

In my work environment, performs paging through several layers, including WCF communication.
In the end pagination is done in the SQL Server, and only returned the rows of the page requested and the total number of pages.

For example
1) Through a Stored Procedure
A procedure that calls the function that will add a row number with ROW_NUMBER () and then to obtain the required page.

2) Through a LINQ to Entities which is in the access layer in a class Repository (pattern repository)

As you will see in any case, only the burgeoning ranks of the requested page, and also as I have out parameters the total number of pages
- How I can assign the total number of pages in the Grid?

EXAMPLE 1:Stored Procedure
ALTER PROCEDURE [dbo].[Productos_Buscar]
@PalabrasABuscar varchar(255),
@PageSize int,
@PageIndex int,
@PageTotal int OUT

DECLARE @FirstRow int,
@LastRow int



SELECT @FirstRow = (@PageIndex - 1) * @PageSize + 1,
@LastRow = (@PageIndex - 1) * @PageSize + @PageSize;
FROM dbo.ProductosCompletosBuscar(@PalabrasABuscar) b
WHERE b.Fila BETWEEN @FirstRow AND @LastRow

SET @PageTotal = (SELECT COUNT(*) FROM dbo.ProductosCompletosBuscar(@PalabrasABuscar))


EXAMPLE 2: LINQ to Entities
public ICollection Listado(string palabrasABuscar, Int32 pageSize, Int32 pageIndex, out Int32 pageTotal)

var query = from p in this.Contexto.Productos
where p.Nombre.Contains(palabrasABuscar)
orderby p.Nombre descending
select p;

pageTotal = query.Count();

return query.Skip(pageSize * pageIndex).Take(pageSize).ToList();

Eswari S [Syncfusion]
Replied On March 31, 2011 01:00 PM UTC

Hi Jose,

Thanks for your update.

We do not assign total number of pages for the grid. By default, number of pages will be calculated from the total number of records in database.

Like, Total number of pages=(Total number of records in Database /PageSize)

PageSize property is used to set the number of records per page and PageCount property is used to set the number of visible pages for the grid at a time. Please refer the below code:


Currently, we don’t have support for CustomBinding in JSON mode. We have logged a feature request for this feature and it will be available in our future releases. However, we do not provide confidential information and patches in the general forum, so could you please create a new incident such that we can provide you the solution as soon as possible.

We have prepared the custom binding sample in ServerMode for your reference. Please find the sample from the attachment.

Note: If you want to run the sample in MVC3, change the configuration manager as Debug MVC3/Release MVC3. To know more about the steps to switch between (Mvc2 to Mvc3) , please refer the document here :

How'>http://help.syncfusion.com/ug_91/User%20Interface/ASP.NET%20MVC/Grid/default.htm?turl=Documents%2F710howtoswitchbetweenmvc2andmvc3assembliesin91version.htm'>How to Switch between MVC2 to MVC3

Please let us know if you need further assistance.




This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon