Forums

ASP

This topic is locked

Recordset Paging and Link to Detail Page

Posted 12 Aug 2006 00:17:30
1
has voted
12 Aug 2006 00:17:30 A. B. posted:
Hello. I try to hand code my ASP, and I need some help with recordset paging.

I've added recordset paging to a very long list of customers (over 3,000 records). I found a recordset paging script online that I've modified to meet my needs, but I can't figure out how to link to a detail page. For example, I want to add icons that the user would click when he/she wants to edit or delete a specific record. Whenever I add the link code, I receive an ASP error.

The edit and delete linked code I use in pages without recordset paging is as follows:

<!-- Placed in the document header -->
<script language="JavaScript">
<!--
function view(ID){
location.href = "edit_customer.asp?ID=" + ID;
}

function remove(ID){
location.href = "delete_customer.asp?ID=" + ID;
}
//-->
</script>

<!-- Placed in sub proc above document header -->
Response.Write "<td valign=""top""><a href=""javascript:view(" & rsCustomers.Fields("ID".Value & ";""><img src=""../images/edit.gif"" border=""0""></a></td>"
Response.Write "<td valign=""top""><a href=""javascript:remove(" & rsCustomers.Fields("ID".Value & ";""><img src=""../images/delete.gif"" border=""0""></a></td>"

I'm sorry I can't post the URL (it's an internal site), but here is the code I am using without the linked edit or delete iconc.

I would appreciate any help that someone can offer me as to how I can add edit and delete icons for a user to select and be taken to the detail pages. Thank you in advance! -Andrea

<% Option Explicit %>
<!--#include file="../connections/connTA.asp" -->
<%
' ADO constants used in this page
Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adCmdTableDirect = &H0200
Const adUseClient = 3
%>
<html>
<head>
<title>Test Recordset Paging</title>
<script language="JavaScript">
<!--
function view(ID){
location.href = "edit_customer.asp?ID=" + ID;
}

function remove(ID){
location.href = "delete_customer.asp?ID=" + ID;
}
//-->
</script>
</head>

<body>
<table width="750" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td width="300"><br><br></td>
<td width="450"><br>
</tr>
<tr>
<td colspan="2" height="40" align="center" valign="middle"><br>
<hr align="center" width="600">
</td>
</tr>
</table>
<table width="750" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td valign="top"><br>
<p>Customers - Click on the edit or delete icon to perform its corresponding action.</p>
<%
Dim rs, oConn
Set oConn = Server.CreateObject("ADODB.Connection"
oConn.Open CONN_STRING

Set rs = Server.CreateObject("ADODB.Recordset"
rs.PageSize = 15
rs.CacheSize = 5
rs.CursorLocation = adUseClient

rs.Open "SELECT CustomerStatus, CustomerTitle, CustomerFirstName, CustomerLastName, CompanyID FROM Customers WHERE CustomerStatus = 'Active' ORDER BY CustomerLastName, CustomerFirstName ASC", oConn 'adOpenForwardOnly, adLockReadOnly, adCmdTableDirect

If Len(Request("pagenum") = 0 Then
rs.AbsolutePage = 1
Else
If CInt(Request("pagenum") <= rs.PageCount Then
rs.AbsolutePage = Request("pagenum"
Else
rs.AbsolutePage = 1
End If
End If

Dim abspage, pagecnt
abspage = rs.AbsolutePage
pagecnt = rs.PageCount

If Not rs.EOF Then
Response.Write "<p>Page " & rs.AbsolutePage & " out of " & rs.PageCount & "<br>" & vbcrlf
Response.Write "Total number of records: " & rs.RecordCount & "</p>" & vbcrlf

Dim fldF, intRec
Response.Write "<table><thead><tr>"
For Each fldF in rs.Fields
Response.Write "<td>" & fldF.Name & "</td>"
Next
Response.Write "</tr></thead><tbody>"

For intRec=1 To rs.PageSize
If Not rs.EOF Then
Response.Write "<tr>"
For Each fldF in rs.Fields
Response.Write "<td>" & fldF.Value & "</td>"
Next
Response.Write "<tr>"
rs.MoveNext
End If
Next
Response.Write "</tbody></table><p>"

' Now show first, next, back, last buttons
Response.Write "<div align=""center"">" & vbcrlf
Response.Write "<a href=""" & Request.ServerVariables("SCRIPT_NAME" & "?pagenum=1"">First Page</a>"
Response.Write " | "

If abspage = 1 Then
Response.Write "<span style=""color:silver;"">Previous Page</span>"
Else
Response.Write "<a href=""" & Request.ServerVariables("SCRIPT_NAME" & "?pagenum=" & abspage - 1 & """>Previous Page</a>"
End If

Response.Write " | "

If abspage < pagecnt Then
Response.Write "<a href=""" & Request.ServerVariables("SCRIPT_NAME" & "?pagenum=" & abspage + 1 & """>Next Page</a>"
Else
Response.Write "<span style=""color:silver;"">Next Page</span>"
End If
Response.Write " | "
Response.Write "<a href=""" & Request.ServerVariables("SCRIPT_NAME" & "?pagenum=" & pagecnt & """>Last Page</a>"
Response.Write "</div><br>" & vbcrlf

Else
Response.Write "No records found!"
End If

rs.Close
Set rs = Nothing
%>
</td>
</tr>
</table><br>
</body>
</html>

Reply to this topic