Go Back   Access World Forums > Apps and Windows > Web Design and Development > ASP and ASP.NET

Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Old 07-22-2014, 08:43 AM   #1
Newly Registered User
Join Date: Feb 2007
Location: United Kingdom
Posts: 2,177
Thanks: 2
Thanked 162 Times in 158 Posts
Simon_MT has a spectacular aura about Simon_MT has a spectacular aura about
Paging using Datasets and DataAdapters

To start each Page has a Page Reference in the QueryString in this OG so we test for LESS THAN 0:

    If Request.QueryString("OG") < 0 Then
        intPage = 1
        intPage = Request.QueryString("OG")
    End If
We will later test for Page GREATER THAN PageCount

Then declare variable from strGrouping from Request.QueryString and some counters
    strGrouping = Request.QueryString("Grouping")
    Dim intCurrentRecord As Integer = 0
    Dim intRecordPos As Integer = 1
    Dim intPageSize As Integer = 6
Construct Connection String and SQL statement. Note that Microsoft.Jet.OLEDB.4.0 is no longer available on some hosting sites.
    connString = "Provider=Microsoft.ACE.OLEDB.12.0;DATA SOURCE= " & Server.MapPath(".\Data\DbName.mdb") & ";Persist Security Info=False;"
   rsSql = "SELECT * FROM OriginalsGrouping WHERE OriginalsGrouping.[Artist Grouping] = '" & strGrouping & "'"
Then populate the DataSet and DataAdapter
    Using conn As New OleDbConnection(connString)

        Dim da As OleDbDataAdapter = New OleDbDataAdapter(rsSql, conn)
        Dim ds As DataSet = New DataSet()

        da.SelectCommand.CommandText = rsSql
        da.Fill(ds, "OriginalsGrouping")
Count the Rows
        intRowCount = ds.Tables(0).Rows.Count
Now determine the Number of Pages, the trick here that as there 6 rows/records per page a new is required on the 7/13/19/25 etc records. Therefore 7+5, 13+5, 19+5, 25+5 need a new Page.
        intPageCount = Int((intRowCount + (intPageSize - 1)) / intPageSize)
Now we test for Request.QueryString("OG") exceeding the number of actual Pages
        If intPage > intPageCount Then
            intPage = intPageCount
        End If
We now set-up the Variables for the For statement
        intStart = intPageSize * (intPage - 1)
        intFinish = intStart + (intPageSize - 1)
Here before the For Statement go the Doc Type and Header MetaTags Body declaration and any container declarations, I use divs.
now for the For statement and counters
    For intRecord = intStart To intFinish
        intRecordPos = intRecord + 1
        intCurrentRecord = intCurrentRecord + 1
At the end of Page including the Exit on the last Row/Record.
End If
If intRecordPos = intRowCount Then
    Exit For
End If
End Using
If you are using right hand side navigation then all you need to do is wait until the Rows/Records have displayed and do this and then inculde the navigational links:
<%  If intCurrentRecord = intPageSize Or intRecordPos = intRowCount Then%>
<div containernav>
These have been declared form the at the beginning :
strGrouping = ds.Tables(0).Rows(0).Item(0).ToString
strGroupingDesc = ds.Tables(0).Rows(0).Item(1).ToString

To add arrows to navigate between pages using Back and Forward arrows and to remove the appropraite arrows on the first and last page:
<%  If CInt(intPage) > 1 Then%>
<a href="<%=Session("Link")%>/Originals_Groupings.aspx?Grouping=<%=strGrouping%>&amp;OG=<%=intPage-1%>" title="<%=Application("keyweb")%> <%=strGroupingDesc%> Large Page <%=intPage-1%>">
<img class="imagenavleft" src="<%=Session("Link")%>/include/back.png" width="11" height="12" alt="<%=Application("keyweb")%> <%=strGroupingDesc%> Large Page <%=intPage-1%>" /></a>
<%  Else%>
<img class="imagenavleft" src="<%=Session("Link")%>/include/fill.gif" width="16" height="12" alt="" />
<%  End If%>
<%  If CInt(intPage) < CInt(intPageCount) Then%>
<a href="<%=Session("Link")%>/Originals_Groupings.aspx?Grouping=<%=strGrouping%>&amp;OG=<%=intPage+1%>">
<img class="imagenavright" src="<%=Session("Link")%>/include/forward.png" width="11" height="12" alt="<%=Application("keyweb")%> <%=strGroupingDesc%> Large Page <%=intPage+1%>" /></a>
<%  Else%>
<img class="imagenavright" src="<%=Session("Link")%>/include/fill.gif" width="16" height="12" alt="" />
<%  End If%>
<div class="cell_nav2_record">
<div class="inforecord">(<%=intStart+1%>-<%=intRecordPos%>&nbsp;of&nbsp;<%=intRowCount%>)</div>
To see how this works here is the actual page:


I forgot to mention to go back to the correct Originals_Grouping.aspx page no matter if you have tranversed pages in the Originals_Grouping_Large.aspx again using 6 images per page

        Session("OG") = Int((intPage - 1) / 6) + 1

<a href="<%=Session("Link")%>/Originals_Groupings.aspx?Grouping=<%=strGrouping%>&amp;OG=<%=Session("OG")%>" title="<%=Application("keyweb")%> <%=strGroupingDesc%> Page <%=Session("OG")%>">

Last edited by Simon_MT; 07-23-2014 at 04:45 PM. Reason: Added going back to Page with Multiple Images
Simon_MT is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Report Footer Paging RayMilhon Reports 1 12-17-2010 03:10 PM
Passing datasets to subroutines GarryBrogden Modules & VBA 13 01-29-2009 04:53 PM
tab paging issue tomro1 Modules & VBA 2 06-01-2008 02:39 PM
Produce frequency for two datasets fredElliotRules Queries 0 11-23-2006 03:19 AM
Alpha Paging TruRob Modules & VBA 1 08-09-2002 08:16 AM

All times are GMT -8. The time now is 07:07 PM.

Microsoft Access Help
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post

Sponsored Links

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World