Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 9th, 2004, 10:24 AM
Registered User
 
Join Date: Jul 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jripke74
Default User choose number records to display per page

I am trying let the user be able to change the number of records to display per page using a HTML form. The problem I am having with this is that it doesn't work it seems to display all the records. Sorry i am quite new to ASP and scrypting. here is the code I used for the form:

<form action="d60Allpage.asp" method="post">
Pictures per page(the more pictures the longer to load):
   <input type="text" name="NumberOfPict" value="20">
   <input type="submit">
</form>


d60Allpage.asp

<%

Const adOpenStatic = 3
Const adLockReadOnly = 1
Const adCmdText = &H0001

Dim CONN_STRING
CONN_STRING = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("d60.mdb")

Dim iPageSize
Dim iPageCount
Dim iPageCurrent
Dim strOrderBy
Dim strSQL
Dim objPagingConn
Dim objPagingRS
Dim iRecordsShown
Dim iFieldCount
Dim iRecordCount
Dim LoopRecordCount
Dim pageNum
Dim counter
Dim markShowPage
Dim I, J

iPageSize = Request.Form("NumberOfPict")

If Request.QueryString("page") = "" Then
    iPageCurrent = 1
Else
    iPageCurrent = CInt(Request.QueryString("page"))
End If

strSQL = "SELECT tblgeneral.dir FROM [tblgeneral] ORDER BY tblgeneral.dateTaken"

Set objPagingConn = Server.CreateObject("ADODB.Connection")
objPagingConn.Open CONN_STRING

Set objPagingRS = Server.CreateObject("ADODB.Recordset")
objPagingRS.PageSize = iPageSize
objPagingRS.CacheSize = iPageSize
objPagingRS.Open strSQL, objPagingConn, adOpenStatic, adLockReadOnly, adCmdText

iPageCount = objPagingRS.PageCount
iFieldCount = objPagingRS.Fields.Count
iRecordCount = objPagingRS.RecordCount

If iPageCurrent > iPageCount Then iPageCurrent = iPageCount
If iPageCurrent < 1 Then iPageCurrent = 1

If iPageCount = 0 Then
    Response.Write "No records found!"
Else
    objPagingRS.AbsolutePage = iPageCurrent

    Dim arrDBData
    ReDim arrDBData(iFieldCount, iRecordCount)
    LoopRecordCount = 0

    'arrDBData = objPagingRS.GetRows()

    Do While LoopRecordCount < iPageSize And Not objPagingRS.EOF
        For I = 0 To objPagingRS.Fields.Count - 1
            arrDBData(I, LoopRecordCount) = objPagingRS.Fields(I)
        Next
        LoopRecordCount = LoopRecordCount + 1
        objPagingRS.MoveNext
    Loop

    objPagingRS.Close
    Set objPagingRS = Nothing
    objPagingConn.Close
    Set objPagingConn = Nothing
End If

iRecordCount = iRecordCount - 1
iFieldCount = iFieldCount - 1
LoopRecordCount = LoopRecordCount - 1

pageNum = Round(iRecordCount/iPageSize)
If pageNum < (iRecordCount/iPageSize) Then pageNum = pageNum + 1

Response.Write "&nbsp;&nbsp;<b> "
'For counter = 1 To pageNum
' if counter=iPageCurrent then
' Response.Write "&nbsp;<span class=activepage>&nbsp;"
' Response.Write counter
' Response.Write "&nbsp;</span>"
' markShowPage=1
' else
' Response.Write "&nbsp;<a onclick=exitoff() href=d60allpage.asp?page="
' Response.Write counter
' Response.Write " class=listingLink>"
' Response.Write counter
' Response.Write "</a>"
' end if
'
'Next

Response.Write "</b>"

Response.Write "&nbsp;&nbsp;"

Response.Write "<b>"

Response.Write "<a href=d60allpage.asp?page="
If iPageCurrent = 1 Then
    Response.Write pageNum
else
    Response.Write iPageCurrent-1
end if


Response.Write " class=listingLink>Back</a>&nbsp;&nbsp;"
Response.Write "<a href=d60allpage.asp?page="
If iPageCurrent = pageNum Then
    Response.Write "1"
else
    Response.Write iPageCurrent+1
end if
Response.Write " class=listingLink>Next</a>"

Response.Write "</b>"

%>
<p>

<table border="1">

<%
For I = 0 To LoopRecordCount
    For J = 0 To ifieldCount
        Response.Write "<a href=" & arrDBData(J, I) & "><img src=" & arrDBData(J, I) & " alt=" & arrDBData(J, I) & " height=133 width=200></img></a>"
    Next ' J
Next ' I
%>

</table>

<%
Response.Write "</b>"

Response.Write "&nbsp;&nbsp;"

Response.Write "<b>"

Response.Write "<a href=d60allpage.asp?page="
If iPageCurrent = 1 Then
    Response.Write pageNum
else
    Response.Write iPageCurrent-1
end if

Response.Write " class=listingLink>Back</a>&nbsp;&nbsp;"
Response.Write "<a href=d60allpage.asp?page="
If iPageCurrent = pageNum Then
    Response.Write "1"
else
    Response.Write iPageCurrent+1
end if
Response.Write " class=listingLink>Next</a>"

Response.Write "</b>"
%>

Thanks in advance,

Jeff
 
Old July 9th, 2004, 11:14 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default

Hi

You could try the following:
<form action="d60Allpage.asp?Var1=<%=request.form("Numbe rOfPict")%>" method="post">

And then on ur asp page go:

iPageSize = Request.QueryString("Var1")

Let me know if this does not solve ur problem

Regards
Marnus
 
Old July 9th, 2004, 11:34 AM
Registered User
 
Join Date: Jul 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jripke74
Default

No that doesn't work I get the following error:

Error Type:
ADODB.Recordset (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/Enter/pictures/d60Allpage.asp, line 84

code:

Set objPagingRS = Server.CreateObject("ADODB.Recordset")
objPagingRS.PageSize = iPageSize
objPagingRS.CacheSize = iPageSize
objPagingRS.Open strSQL, objPagingConn, adOpenStatic, adLockReadOnly, adCmdText



 
Old July 11th, 2004, 06:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

CursorLocation - In order to use recordset paging, you will need to set this value to "adUseClient".

I don't see you using that property of RECORDSET in your code. You can take a look at these pages for better understanding of RECORSET properties being used for paging.

Recordset Paging with ADO 2.0

ADO Recordset Paging in ASP

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old July 12th, 2004, 11:19 AM
Registered User
 
Join Date: Jul 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jripke74
Default

It works!!!:D

Thanks for your help in pointing me in the right direction. Learned allot.

Thanks again

Jeff:)






Similar Threads
Thread Thread Starter Forum Replies Last Post
I need to display 15 records per page only dreamer_0244 Crystal Reports 0 November 19th, 2007 04:16 AM
Gridview number of records display jodojan ASP.NET 2.0 Basics 3 April 14th, 2007 05:29 AM
Choose all records from 2 weeks ago?? morpheus Classic ASP Databases 4 January 9th, 2007 01:00 PM
how to pass value to new page and display records method ASP.NET 1.0 and 1.1 Basics 0 March 14th, 2005 09:34 AM
user input number of records bubblez Classic ASP Databases 0 October 21st, 2003 08:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.