Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 paging and asp.net

Author  Topic 

vishal_7
Posting Yak Master

127 Posts

Posted - 2005-03-09 : 15:53:53
Hello,

I am currently doing paging via a stored procedure. Its this one.

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


--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


This is a standard procedure, which I found in an article. I used this procedure changed the tables, fields, added some parameters etc and it works sofar.

In my asp.net page I am retrieving data from the database to build a datalist. Now the parameters which are required for the stored procedure are stored in the viewstate - not the Page or RecsPerPage parameter. Above the webform I have two links, one for next and one for prev. These links are set to something like that:

page.aspx?Page=1

However the problem is that since its a new http request, the user is somehow forced to reenter the data and rebind the datalist. Is there any workaround for that? Becuase otherwise the paging is useless, when the user can page. I hope you guys understand what I mean.

Any help is very appreciated.
Thanks

bmains
Starting Member

27 Posts

Posted - 2005-03-18 : 13:36:18
Is your problem that the page and recsperpage are being lost because of the querystring variables? Consider using the LinkButton and storing the current page in the viewstate (or something like that) instead, that way when the user clicks next/prev, the page will perform a postback and not be considered a new http request.

Brian
Go to Top of Page
   

- Advertisement -