Paging in my web page
I have a large data set and i have to apply paging on that data set and after that the result set should be another data set. What is the reliable method to achieve that.
I have tried with 'PagedDataSource' class but i don't know how it is possible to convert to dataset or data table.
In my case i need a general solution. I have t开发者_运维百科o bind to a control like gridview as well as i have to used it with normal html table.
check this article doing same thing you want : http://www.codeproject.com/KB/custom-controls/EnhanceGrid.aspx
following sp returns record that you want
CREATE PROCEDURE [dbo].[GetRequestedRecordByPage]
@FromList nvarchar(200) -- Table Name
,@SortingCol nvarchar(200) -- Sorting column Name
,@SelectList nvarchar(200) = '*' -- Select columns list
,@WhereClause nvarchar(200) = '' -- Where clause i.e condition
,@PageNum int = 1 -- Requested page number
,@PageSize int = 5 -- No of record in page
,@TotalNoOfRecord int output -- Total no of selected records
AS
Begin
SET NOCOUNT ON
DECLARE @Query nvarchar(max) -- query going to be execute
IF rtrim(ltrim(@WhereClause)) <> ''
BEGIN
SET @Query ='SELECT @TotalNoOfRecord = COUNT(*)
FROM ' + @FromList + '
WHERE ' + @WhereClause
END
ELSE
BEGIN
SET @Query ='SELECT @TotalNoOfRecord = COUNT(*)
FROM ' + @FromList
END
/* Count no. of record */
EXEC sp_executeSQL
@Query,
@params = N'@TotalNoOfRecord INT OUTPUT',
= @TotalNoOfRecord OUTPUT
DECLARE @lbound int, @ubound int
/* Calculating upper and lower bound */
SET @lbound = ((@PageNum - 1) * @PageSize)
SET @ubound = @lbound + @PageSize + 1
/* Get list of record(s) */
SELECT @Query = ''
SELECT @Query = 'SELECT *
FROM (
SELECT ROW_NUMBER() OVER(ORDER BY ' + @SortingCol + ') AS rownumber,' +@SelectList +
' FROM ' + @FromList
IF rtrim(ltrim(@WhereClause)) <> ''
BEGIN
SELECT @Query = @Query + ' WHERE ' + @WhereClause
END
SELECT @Query = @Query + ' ) AS tbl
WHERE rownumber > ' + CONVERT(varchar(9), @lbound) +
' AND rownumber < ' + CONVERT(varchar(9), @ubound)
EXEC (@Query)
End
精彩评论