Abundant Technologies - IT Consulting Experts

 Source Code Library

 Code Details

 
<% 'How many records per page do we want to show? Const iRecordsPerPage = 10 Dim currentPage 'what page are we on?? Dim bolLastPage 'are we on the last page? if len(Request.QueryString("page")) = 0 then currentPage = 1 else currentPage = CInt(Request.QueryString("page")) end if 'Show the paged results strSQL = "sp_PagedItems " & currentPage & "," & iRecordsPerPage objRS.Open strSQL, objConn 'See if we're on the last page if Not objRS.EOF then if CInt(objRS("MoreRecords")) > 0 then bolLastPage = False else bolLastPage = True end if end if %>

<% Do While Not objRS.EOF %> <% objRS.MoveNext Loop %>
List of Items
<%=objRS("Name")%> <%=FormatCurrency(objRS("Price"))%>

<% 'Only show the previous button if we are NOT on the first page if currentPage > 1 then %>       <% end if 'Only show the next button if we are NOT on the last page if Not bolLastPage then %> <% end if %>
//SQL Server Stored Procedure sp_PagedItems CREATE PROCEDURE sp_PagedItems ( @Page int, @RecsPerPage int ) AS -- We don't want to return the # of rows inserted -- into our temporary table, so turn NOCOUNT ON SET NOCOUNT ON -- Find out where we will start our records from DECLARE @RecCount int SELECT @RecCount = @RecsPerPage * @Page + 1 --Create a temporary table CREATE TABLE #TempItems ( ID int IDENTITY, Name varchar(50), Price currency ) -- Insert the rows from tblItems into the temp. table INSERT INTO #TempItems (Name, Price) SELECT Name,Price FROM tblItem ORDER BY Price -- Find out the first and last record we want DECLARE @FirstRec int, @LastRec int SELECT @FirstRec = (@Page - 1) * @RecsPerPage SELECT @LastRec = (@Page * @RecsPerPage + 1) -- Now, return the set of paged records, plus, an indiciation of we -- have more records or not! SELECT *, MoreRecords = ( SELECT COUNT(*) FROM #TempItems TI WHERE TI.ID > @LastRec ) FROM #TempItems WHERE ID > @FirstRec AND ID < @LastRec -- Turn NOCOUNT back OFF SET NOCOUNT OFF

Mail To: info@3pc.com