|
My usual approach is to return the required records and the total number of eligible records in the data layer.
Then customize a page navigation control to display the corresponding page number!
The following is a code snippet of my data layer when paginating. Based on SQL 2005
StringBuilder strSQL = new StringBuilder ();
strSQL.Append ("SELECT * FROM (");
strSQL.Append ("SELECT ProductID, ProductNO, CategoryID, CategoryTitle, ProductName, MarketPrice, MemberPrice, ProductParams, Description, ImagesCount, CreateDate, ROW_NUMBER () OVER (Order By ProductID Desc) AS RowNum from Product");
strSQL.Append (") AS T WHERE RowNum BETWEEN @StartRow AND @EndRow");
IList <ProductInfo> tList = new List <ProductInfo> ();
SqlParameter [] parameters = {
new SqlParameter ("@ StartRow", SqlDbType.Int),
new SqlParameter ("@ EndRow", SqlDbType.Int)
};
parameters [0] .Value = (index-1) * pagesize;
parameters [1] .Value = index * pagesize; |
|