Back to Top
The nuts and bolts for
Creative web development

Free! - Selecting Records per Page with the Horizontal Looper Behaviour

This tutorial shows how to let the visitor select the number of records per page from a List Box using Tom Muck’s Horizontal Looper Extension.

Since there will be probably be several pages on your site with this behaviour, we are going to use a Session to store the visitor’s choice so it will be valid on all the pages, instead of the visitor having to set the number of records on each page they visit.

Overview

Set up your recordset as normal and apply the Horizontal Looper behaviour

Insert a form with a list box.

<form name="form1" method="post" action="yourpage.asp">

      Records per Page

        <select name="select" >

          <option>Select</option>

          <option value="2">8</option>

          <option value="3">12</option>

          <option value="4">16</option>

          <option value="5">20</option>

          <option value="6">24</option>

        </select>

        <input type="submit" name="Submit" value="Go">

     

    </form>

In your option values, use the number of records divided by the number of columns you want on your page. If you have four columns, then 8 records per page is a value of 2.

Next, set the session –

<%

If Request.Form("select") ="" then

If Session("paging") <>"" then

Session("paging") = Session("paging")

End If

End If

If Request.Form("select") <> "" then

Session("paging") = Request.Form("select")

End If

%>

This also prevents the Session being set to zero when the visitor pages through the records. If the visitor enters a new value, the Session will update to that value.

Now you have to modify the Horizontal Looper code.

Change the code to set the number of rows (the default value here is 8 to have 2 rows of 4 columns, but you can make that 9 and change the multiplier further down from 4 to 3 to give 3 rows of 3 columns)

<%

Dim HLooper1__numRows

If Session("paging") ="" then

HLooper1__numRows = 8

Else

HLooper1__numRows = 4 * Session("paging")

End If

Dim HLooper1__index

HLooper1__index = 0

Recordset1_numRows = Recordset1_numRows + HLooper1__numRows

%>

Now the final part. Modify the code as follows,

<%

startrw = 0

endrw = HLooper1__index

numberColumns = 4

if Session("paging") = "" then

numrows = 2

Else

numrows = Session("paging")

End If

%>

Make sure you set the numberColumns and numrows to the default values you set earlier.

It’s that easy! You can apply the first, next, previous behaviours as normal.

Share this Article