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
Question:
- 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
AS
DECLARE @FirstRow int,
@LastRow int
BEGIN
SET NOCOUNT ON;
SELECT @FirstRow = (@PageIndex - 1) * @PageSize + 1,
@LastRow = (@PageIndex - 1) * @PageSize + @PageSize;
SELECT
b.*
FROM dbo.ProductosCompletosBuscar(@PalabrasABuscar) b
WHERE b.Fila BETWEEN @FirstRow AND @LastRow
SET @PageTotal = (SELECT COUNT(*) FROM dbo.ProductosCompletosBuscar(@PalabrasABuscar))
END
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();
}