Click to See Complete Forum and Search --> : Pagination in ASP
Brachole
02-20-2009, 11:26 AM
Hi, is there an Extension for Dreamweaver or tutorial on how to create a pagination on a Reslt page in ASP? I have this database and when a user search for a product, I'm only displaying 25 products per page. I have added a "Next" and "Previous" button but what if I wanted to added page numbers? Example is:
Previous 1 2 3 4 5 6 7 8 9 10 Next
I'd like to know how to make this.
Thank you!
yamaharuss
02-20-2009, 01:48 PM
Seems that would be simple math.
numRecords/25 = numPages
From there just display your page numbers any way you like.
Kuriyama
03-02-2009, 11:06 AM
ADODB.RecordSet Object will allow you to do this, but it's slow. You should always try to take care of your paging with clever SQL queries if possible.
nbcrockett
03-03-2009, 08:23 AM
This got me started with paging.
http://www.asp101.com/samples/db_paging.asp
pmatah
03-04-2009, 07:07 PM
Here are a couple more helpful links:
http://weblogs.asp.net/shijuvarghese/archive/2008/07/23/asp-net-mvc-grid-view-using-mvccontrib.aspx
and
http://forums.asp.net/p/997097/1309186.aspx#1309186
and a user control: http://code-inside.de/blog-in/2008/04/08/aspnet-mvc-pagination-view-user-control/
Hope that helps!
Parul
[MSFT]
TonyLoco23
03-09-2009, 04:52 PM
Dont make the same mistake I made. I waisted many many hours developing my own pagination code, about 25 hours of work and 3 websites later, I am still having some minor issues with it.
You'd probably be better off looking to buy some ready made downloadable component for $10-$25 or something. Google it.
Kuriyama
03-10-2009, 09:10 AM
"You'd probably be better off looking to buy some ready made downloadable component for $10-$25 or something."
ADODB.RecordSet Object is free and will more or less handle paging for you. It's mind numbingly easy to implement.
If you are spending more than 25 hours making paging work, then you are making it more complicated than it needs to be. Write SQL queries that return only the records that you need.
TonyLoco23
03-10-2009, 10:46 AM
Write SQL queries that return only the records that you need.
So you are saying that you store the total number of records in a session variable or in the URL and then you would just do a new recordset call to the database each time the user selects to go to another page of results?
How would you even know which records to select if the results are sorted by a field other than ID? For example often pagination results are sorted by time, or alphabetically.
Kuriyama
03-10-2009, 11:04 AM
Takes a little more SQL knowledge but preformance wise, this is hands down the fastest way to do paging.
Let's say you are pulling information of a table name product.
Find the total number of records with 1 query.
Select count(sku) as total from product Now use simple math to figure out the number of pages.
Now return the request page and ONLY that page. This would return page 2 showing 10 results.
select top 20 [page number * page count] * from product_master
where sku NOT IN(SELECT top 10 [(page number * page count) - page count] sku from product_master ORDER BY sku DESC)
ORDER BY sku DESC
Now you don't have to do any cursor advancement to the correct page. You only the records that you want. It takes a little more SQL knowledge, but this way is best for performance.
Make sense?