vishal_adorable4u
vishal_adorable4u

Reputation: 1

Pagination in Classic ASP with VB Script

I am using ASP/VB Script in my project but, i don't have much idea of Pagination in Classic ASP. I have designed a datagrid format using tables and looping. That table is filled by accessing database. As we have a huge amount of data to display, we need pagination.

Thanks in advance

Upvotes: 0

Views: 5193

Answers (3)

There is a issue you need to be aware of... the built-in ASP record set will allow pagiing, however is not very efficient. The entire result set gets returned to the browser and then it locates the appropriate page and displays that data.

Think of it like this... your result set is a 4 shelf book case. When you ask for page one all 4 shelves of books get returned. The the display code says "Okay now only show page 1". If you then ask for page two... All four shelves of books gets returned and then the display code says "Okay give me page 4".

So, you should look for a paging solution that takes place on the server, inside the database. This way if you ask for page 15 of a 50 page result, the database will only return one shelf of books.

This google query should put you on the right track.

Edit: How SQL Paging Works

  1. You must us a stored procedure
  2. One of the input parameters is the page to view
  3. The stored procedure filters the results on the server

Here is the basic concept of what happens inside the proc:

Step 1:
Create a temp table that stores the entire result set. My preference is to store only two values in this temp table. An identity seed value called RowId and the primary key of the result data. (I'm one of those people that believes in non-sensical identity seed keys)

Step 2:
Insert all the PKey values from the select statement into the temp table

Step 3:
Determine the StartRowId and EndRowId based on the input page parameter.

Step 4:
Select from the temp table using an inner join to the datatable on the PKey. In the where clause limit the result so the RowId (of the temp table) is between StartRowId and EndRowId. Make sure to Order By the RowId.

Upvotes: 1

Eduardo Molteni
Eduardo Molteni

Reputation: 39413

The pagination problem is not inherently to ASP classic or VBScript. You need first to define which strategy to follow:

In the client:

  1. Ajax style pagination (You can use a jQuery plugin like SlickGrid)
  2. Linked pagination: Your page have links to page 1, page 2, etc.
  3. Infite scrolling: This is a modern way to do pagination, with more results added to the page via ajax

In the server

  1. Full DB results retrieve and return only the page asked. This is sometimes necessary.
  2. Full DB retrieve but caching the result so subsequent page request come from the cache, not the DB
  3. Ask the DB only the page asked (Different techniques depending on the DB engine)

Upvotes: 2

CM Kanode
CM Kanode

Reputation: 1436

Set page size

recordset.PageSize = 100 ' number of records per page

Set the current page

recordset.AbsolutePage = nPage ' nPage being the page you want to jump to.

Other useful bits:

recordset.RecordCount ' number of records returned
recordset.PageCount ' number of pages based on PageSize and RecordCount

That's the basic info. You'll still need to loop through the appropriate number of records, and check the page number as it is passed back to the page.

Upvotes: 0

Related Questions