...

View Full Version : code on paging



Squall Leonhart
11-24-2003, 08:08 PM
Hi, guys.
I have question on paging.
Please take a look at this code.



<HTML>
<HEAD>
</HEAD>
<BODY LEFTMARGIN=0 MARGINWIDTH="0" MARGINHEIGHT="0">
<%
'Dimension variables
Dim todaysDate
Dim adoCon 'Holds the Database Connection Object
Dim rsGuestbook 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query for the database
Dim Page
Dim RowCount
Dim PageCounter

Page = Request.QueryString("Page")

'If there is no page set it to page 1
If Page = "" then
Page = 1
End if

RowCount = 0

Set adoCon = Server.CreateObject("ADODB.Connection")
Set rsGuestbook = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM tblMSI ORDER BY ID DESC"
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("guestbook.mdb")
rsGuestbook.CursorType = 3
rsGuestbook.PageSize = 10
rsGuestbook.Open strSQL, adoCon
rsGuestbook.AbsolutePage = cInt(Page)
%>
<TABLE width="576" border="1" align="center" nowrap >
<br>
<tr>
<td colspan="7">
<DIV align="Center"><b>MSI.FYI Listings </b>- Current page <B><%=Request.Querystring("page")%></b></DIV>
</td>
</tr>
<% Do while not rsGuestbook.eof and RowCount < rsGuestbook.PageSize %>
<tr>
<td width="28">#<% Response.Write (rsGuestbook("ID")) %></td>
<td width="134"><% Response.Write FormatDateTime(rsGuestbook("Date"),2) %></td>
<td width="377"><a href="guestbook.asp?ID=<%=rsGuestbook("ID")%>" target="_blank"> MSI.FYI#<% Response.Write (rsGuestbook("ID")) %>&nbsp; <% Response.Write (rsGuestbook("title")) %></td>
</tr>
<% 'Write the HTML to display the current record in the recordset
rsGuestbook.Movenext
RowCount = RowCount + 1
Loop
%>
<tr>
<td bordercolor="#666666" align="Middle">
<%For PageCounter = 1 to rsGuestbook.PageCount %>
<A href='msi_fyi.asp?Page=<%=PageCounter %>' class='myclass'>Page&nbsp<%=PageCounter %></a>
&nbsp&nbsp&nbsp
<%Next%>
</td>
</tr>
</table>
<%'Reset server objects
rsGuestbook.Close
Set rsGuestbook = Nothing
Set adoCon = Nothing
End if
%>
</BODY>
</HTML>


As you can see, this code generates link like page1, page2, page3, and so on.
If there is 100 pages total, it will go on like page1, page2.....page100. Then it's too much.

So how can I show page1, page2 ,page3, page4, page5-> and if I click ->, and I want to move to <-page6, page7,page8,page9,page10 ->.
And when I reach final page, I want to show it like this
<-page96, page97,page98,page99,page100.
Do you guys encounter this problem before?
Please help me. Thanks.

jeskel
11-24-2003, 08:34 PM
got it from ASP101 right? ;) why not make a drop down with all the pages to display? That's what I do with paging. You can go to the page you want anytime without clicking multiple times... If that solution interests you, let me know...

jeskel
11-24-2003, 08:39 PM
I mean you can have a dropdown list generated dynamicly that will display as many lines as there are pages, and you'll have something like this in your dropdown:

go to page 1 of "x"
go to page 2 of "x"
go to page 3 of "x"
go to page 4 of "x"
...
go to page 167 of "x"

where x is the highest page you have. You can easily do that using a for loop... Much more userfriendly as far as I'm concerned...

Squall Leonhart
11-24-2003, 09:34 PM
Thanks for reply.
But I never seen anyone use dropdown box for paging.
Can I do the way I suggested above in the first place?

jeskel
11-24-2003, 10:25 PM
Originally posted by Squall Leonhart
Thanks for reply.
But I never seen anyone use dropdown box for paging.
Can I do the way I suggested above in the first place?
huh? I see that all the time because it makes nav much easier (you can see an example of that on hotmail.com). If you plan to have ahundred pages and that someone wants to go to page 87, he'll have to make a couple of clicks to acceed that page. Only one with the dropdown solution... But well... it's your call...

Squall Leonhart
11-24-2003, 10:42 PM
Or I want paging like this website forum's paging.
How can I do that?:(

raf
11-24-2003, 11:30 PM
In any case, i would recommend using the GetRows-method on the recordsetobject if your doing recordset paging.

Here's a small tutorial with example code

http://www.devhome.org/asp/

http://www.juicystudio.com/tutorial/asp/getrows.asp

I don't think they are the best script one could write, but they seam decent.
Or you can google for 'recordset paging GetRows' ...

Squall Leonhart
11-24-2003, 11:39 PM
Above examples are kinda hard for me
So I changed code like this


code:--------------------------------------------------------------------------------
<HTML>
<HEAD>
</HEAD>
<BODY LEFTMARGIN=0 MARGINWIDTH="0" MARGINHEIGHT="0">
<%
'Dimension variables
Dim todaysDate
Dim adoCon 'Holds the Database Connection Object
Dim rsGuestbook 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query for the database
Dim Page
Dim RowCount
Dim PageCounter

Page = Request.QueryString("Page")

'If there is no page set it to page 1
If Page = "" then
Page = 1
End if

RowCount = 0

Set adoCon = Server.CreateObject("ADODB.Connection")
Set rsGuestbook = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM tblMSI ORDER BY ID DESC"
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("guestbook.mdb")
rsGuestbook.CursorType = 3
rsGuestbook.PageSize = 10
rsGuestbook.Open strSQL, adoCon
rsGuestbook.AbsolutePage = cInt(Page)
%>
<TABLE width="576" border="1" align="center" nowrap >
<br>
<tr>
<td colspan="7">
<DIV align="Center"><b>MSI.FYI Listings </b>- Current page <B><%=Request.Querystring("page")%></b></DIV>
</td>
</tr>
<% Do while not rsGuestbook.eof and RowCount < rsGuestbook.PageSize %>
<tr>
<td width="28">#<% Response.Write (rsGuestbook("ID")) %></td>
<td width="134"><% Response.Write FormatDateTime(rsGuestbook("Date"),2) %></td>
<td width="377"><a href="guestbook.asp?ID=<%=rsGuestbook("ID")%>" target="_blank"> MSI.FYI#<% Response.Write (rsGuestbook("ID")) %> <% Response.Write (rsGuestbook("title")) %></td>
</tr>
<% 'Write the HTML to display the current record in the recordset
rsGuestbook.Movenext
RowCount = RowCount + 1
Loop
%>
<tr>
<td bordercolor="#666666" align="Middle">
<%
Dim start
Dim finish

If Page < 5 Then
start = 1
finish = 5
ElseIf rsGuestbook.PageCount - Page < 5 Then
start = rsGuestbook.PageCount - 4
finish = rsGuestbook.PageCount
Else
start = Page - 5
finish = Page + 5
End If

For i = start To finish
If Not i = Int(Page) Then
%>
<a href="msi_fyi.asp?Page=<%=i%>"> Page <%=i%> </a>
<%
Else
Response.Write " Page " & i
End If
Next
%>
</td>
</tr>
</table>
<%'Reset server objects
rsGuestbook.Close
Set rsGuestbook = Nothing
Set adoCon = Nothing
End if
%>
</BODY>
</HTML>
--------------------------------------------------------------------------------

But still doesn't work. I don't know where is the problem.
I wanted to show it like

quote:
--------------------------------------------------------------------------------
Page1,Page2, Page3,Page4,Page5 Next

Squall Leonhart
11-25-2003, 10:25 PM
Please help me, guys.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum