Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP, Page through and Show In columns

Status
Not open for further replies.

help120

Technical User
Apr 15, 2001
198
0
0
US
I'm trying to show 3 records across and 3 records down on my page. Then I want to be able to page to the next set of records and do the same thing. The code I'm using now kind of works.. It lists the id in the columns but will not page through my record set. If I could get some help I would very apreciative.


MY CODE!

_____________________________________________


<%
DIM objConn
Set objConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
objConn.ConnectionString = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & _
Server.MapPath (&quot;/testsites/crazy/db/cart.mdb&quot;) & &quot;;&quot;
objConn.Open

DIM mySQL
mySQL = &quot;SELECT * FROM products&quot;

DIM objRS
Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
objrs.CursorLocation = 3 ' adUseClient
objRS.Open mySQL, objConn
objrs.PageSize = 3
intPageCount = objrs.PageCount

Select Case Request(&quot;Action&quot;)
case &quot;<<&quot;
intpage = 1
case &quot;<&quot;
intpage = Request(&quot;intpage&quot;)-1
if intpage < 1 then intpage = 1
case &quot;>&quot;
intpage = Request(&quot;intpage&quot;)+1
if intpage > intPageCount then intpage = IntPageCount
Case &quot;>>&quot;
intpage = intPageCount
case else
intpage = 1
end select


DIM recCount
IF Not objRS.EOF THEN
Response.Write &quot;<table width=100>&quot;
recCount = 0
Do WHILE NOT objRS.EOF
IF recCount Mod 3 = 0 THEN
IF recCount <> 0 THEN Response.Write &quot;</tr>&quot;
Response.Write &quot;<tr><td>&quot;&objRS(&quot;id&quot;)&&quot;</td>&quot;
ELSE
Response.Write &quot;<td>&quot;&objRS(&quot;id&quot;)&&quot;</td>&quot;
END IF
recCount = recCount + 1
objRS.MoveNext
Loop
Response.Write&quot;</tr></table>&quot;
ELSE Response.Write &quot;Sorry, there are no records in our database.&quot;
END IF
%>
<%
objrs.AbsolutePage = intPage
For intRecord = 1 To objrs.PageSize
%>
<%
objrs.MoveNext
If objrs.EOF Then Exit For

Next

objrs.Close
set objrs = Nothing
%>
<form name=&quot;MovePage&quot; action=&quot;test.asp&quot; method=&quot;post&quot;>
<input type=&quot;hidden&quot; name=&quot;intpage&quot; value=&quot;<%=intpage%>&quot;>
<input type=&quot;submit&quot; name=&quot;action&quot; value=&quot;&lt;&lt;&quot;>
<input type=&quot;submit&quot; name=&quot;action&quot; value=&quot;&lt;&quot;>
<input type=&quot;submit&quot; name=&quot;action&quot; value=&quot;&gt;&quot;>
<input type=&quot;submit&quot; name=&quot;action&quot; value=&quot;&gt;&gt;&quot;>
Page: <%=Intpage & &quot; of &quot; & intpagecount%>
</form>
 
send us ur cart.mdb save me creating one to gsc1ugs@yahoo.co.uk Regards gsc1ugs
&quot;Cant see wood for tree's...!&quot;
 
I fixed the paging problem but now it will not move onto the next set of records when it changes to the next page.

This is what I changed in the code:

Do WHILE NOT objRS.EOF

To:

Do While recCount < objrs.PageSize AND Not objRS.EOF
 
I'll look again... thought this was different thread Regards gsc1ugs
&quot;Cant see wood for tree's...!&quot;
 
DIM currentPage

IF Request.Querystring(&quot;page&quot;) = &quot;&quot; THEN
currentPage = 1
ELSE
currentPage = Request.Querystring(&quot;page&quot;)
END IF

DIM totalPages

SET rs = cn.Execute(&quot;SELECT Count(*) AS cnt FROM Table&quot;)

rs.MoveFirst

totalPages = INT(rs(&quot;cnt&quot;)/3) + 1

rs.Close
SET rs = NOTHING

SQL = &quot;SELECT TOP 3 * FROM Table &quot;
IF currentPage > 1 THEN
SQL = SQL & &quot; WHERE [PrimaryKey] NOT IN (SELECT TOP &quot; & 3 * currentPage & &quot;[PrimaryKey] FROM Table)&quot;
END IF

'LOOP THROUGH QUERY TO PRODUCE TABLE

IF currentPage > 0 THEN
<A href=&quot;thispage?page=<%= currentPage - 1 %>&quot;>
Previous
</a>
END IF
IF currentPage < totalPages THEN
<A href=&quot;thispage?page=<%= currentPage + 1 %>&quot;>
Next
</a>
END IF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top