Forums
This topic is locked
Move to next item on detail page
Posted 13 Sep 2002 00:55:53
1
has voted
13 Sep 2002 00:55:53 John Ambrose posted:
Hi all, I have results returned from several tables in a database and compiled into one asp screen. One of the fields returned is being used as a hyperlink to a detail screen. This detail screen gives more information about the item chosen. On the detail screen, I would like to have a next button that would scroll down the previous screen and display the results on the detail screen instead of going back to the results screen and hitting another hyperlink. How can this be done?????? Any ideas???? ThanksEdited by - john22 on 13 Sep 2002 01:00:44
Edited by - john22 on 13 Sep 2002 01:01:10
Replies
Replied 17 Sep 2002 00:13:03
17 Sep 2002 00:13:03 Ned Frankly replied:
It sounds simple enough to just pass the 'next' ID along with the current one, but that only works the first time through - on the second record, it has no idea what the 'next' record should be.
I was intrigued so I created a small test. I created a table called Categories in a database called Test. Categories has two fields: CategoryID and Category.
I then created two recordsets - one that filters for the current record (where CategoryID = varCatID) and one that lists all records in Categories. My tables are rsTest and rsTestAll. I decided to do a Previous and Next.
The critical block of code starts at rsTestAll.MoveFirst();. Also note the conditionals on the display (I put them in a 3 cell table) that hide the Previous and Next links on the first and last records (respectively).
It works - may not be the most efficient, but hey... Here's the code in all its glory:
<%@LANGUAGE="JAVASCRIPT"%>
<!--#include file="Connections/test.asp" -->
<%
var rsTest__varCatID = "0";
if (String(Request.QueryString("CatID") != "undefined" &&
String(Request.QueryString("CatID") != "" {
rsTest__varCatID = String(Request.QueryString("CatID");
}
%>
<%
var rsTest = Server.CreateObject("ADODB.Recordset"
rsTest.ActiveConnection = MM_test_STRING;
rsTest.Source = "SELECT * FROM Categories WHERE CategoryID = "+ rsTest__varCatID.replace(/'/g, "''" + "";
rsTest.CursorType = 0;
rsTest.CursorLocation = 2;
rsTest.LockType = 1;
rsTest.Open();
var rsTest_numRows = 0;
%>
<%
var rsTestAll = Server.CreateObject("ADODB.Recordset"
rsTestAll.ActiveConnection = MM_test_STRING;
rsTestAll.Source = "SELECT * FROM Categories ORDER BY CategoryID";
rsTestAll.CursorType = 0;
rsTestAll.CursorLocation = 2;
rsTestAll.LockType = 1;
rsTestAll.Open();
var rsTestAll_numRows = 0;
%>
<%
rsTestAll.MoveFirst();
var PreviousLink = 0;
var NextLink = 0;
var AllDone = 0;
while (!rsTestAll.EOF && !AllDone) {
if (rsTest__varCatID ==rsTestAll.Fields.Item("CategoryID".Value) {
rsTestAll.MoveNext();
if (!rsTestAll.EOF) { NextLink = rsTestAll.Fields.Item("CategoryID".Value; }
else NextLink = 0
AllDone = 1;
}
else {
PreviousLink = rsTestAll.Fields.Item("CategoryID".Value;
rsTestAll.MoveNext();
}
}
%>
<html>
<head>
<title>Test Next and Previous navigation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<td><%if (PreviousLink){%><a href="index.asp?CatID=<%=PreviousLink%>">Previous=<%=PreviousLink%></a><%}%></td>
<td><%=(rsTest.Fields.Item("Category".Value)%></td>
<td><%if (NextLink){%><a href="index.asp?CatID=<%=NextLink%>">Next=<%=NextLink%></a><%}%></td>
</tr>
</table>
</body>
</html>
<%
rsTest.Close();
%>
<%
rsTestAll.Close();
%>
Ned Frankly
Edited by - NedFrankly on 17 Sep 2002 00:25:23
Edited by - NedFrankly on 17 Sep 2002 00:29:29
I was intrigued so I created a small test. I created a table called Categories in a database called Test. Categories has two fields: CategoryID and Category.
I then created two recordsets - one that filters for the current record (where CategoryID = varCatID) and one that lists all records in Categories. My tables are rsTest and rsTestAll. I decided to do a Previous and Next.
The critical block of code starts at rsTestAll.MoveFirst();. Also note the conditionals on the display (I put them in a 3 cell table) that hide the Previous and Next links on the first and last records (respectively).
It works - may not be the most efficient, but hey... Here's the code in all its glory:
<%@LANGUAGE="JAVASCRIPT"%>
<!--#include file="Connections/test.asp" -->
<%
var rsTest__varCatID = "0";
if (String(Request.QueryString("CatID") != "undefined" &&
String(Request.QueryString("CatID") != "" {
rsTest__varCatID = String(Request.QueryString("CatID");
}
%>
<%
var rsTest = Server.CreateObject("ADODB.Recordset"
rsTest.ActiveConnection = MM_test_STRING;
rsTest.Source = "SELECT * FROM Categories WHERE CategoryID = "+ rsTest__varCatID.replace(/'/g, "''" + "";
rsTest.CursorType = 0;
rsTest.CursorLocation = 2;
rsTest.LockType = 1;
rsTest.Open();
var rsTest_numRows = 0;
%>
<%
var rsTestAll = Server.CreateObject("ADODB.Recordset"
rsTestAll.ActiveConnection = MM_test_STRING;
rsTestAll.Source = "SELECT * FROM Categories ORDER BY CategoryID";
rsTestAll.CursorType = 0;
rsTestAll.CursorLocation = 2;
rsTestAll.LockType = 1;
rsTestAll.Open();
var rsTestAll_numRows = 0;
%>
<%
rsTestAll.MoveFirst();
var PreviousLink = 0;
var NextLink = 0;
var AllDone = 0;
while (!rsTestAll.EOF && !AllDone) {
if (rsTest__varCatID ==rsTestAll.Fields.Item("CategoryID".Value) {
rsTestAll.MoveNext();
if (!rsTestAll.EOF) { NextLink = rsTestAll.Fields.Item("CategoryID".Value; }
else NextLink = 0
AllDone = 1;
}
else {
PreviousLink = rsTestAll.Fields.Item("CategoryID".Value;
rsTestAll.MoveNext();
}
}
%>
<html>
<head>
<title>Test Next and Previous navigation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<td><%if (PreviousLink){%><a href="index.asp?CatID=<%=PreviousLink%>">Previous=<%=PreviousLink%></a><%}%></td>
<td><%=(rsTest.Fields.Item("Category".Value)%></td>
<td><%if (NextLink){%><a href="index.asp?CatID=<%=NextLink%>">Next=<%=NextLink%></a><%}%></td>
</tr>
</table>
</body>
</html>
<%
rsTest.Close();
%>
<%
rsTestAll.Close();
%>
Ned Frankly
Edited by - NedFrankly on 17 Sep 2002 00:25:23
Edited by - NedFrankly on 17 Sep 2002 00:29:29
Replied 17 Sep 2002 00:41:32
17 Sep 2002 00:41:32 Ned Frankly replied:
Oh, and on the multiple tables on one page - you will have to combine the recordsets for this method to work, or modify the looper to go through each individual recordset. The important thing is to make sure that the recordset(s) you use on the detail page to drive the Previous/Next are identical to the ones you used on the master list page.
I'd really like to see it when you're done.
Ned Frankly
I'd really like to see it when you're done.
Ned Frankly