How to write out hyperlink from a Recordset, then click the hyperlink to view a complete listing of

Contributed by
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
September 01, 1999
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement
Here is the code used in the demo!

Page One - The page that shows a table like the one above.

<%@ Language = "VBScript"%>
<%
response.buffer = true
On Error Resume Next
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("hyperlinkdemo.mdb")
'Declare all variables
dim conn
dim rs
dim strID
dim strconn
dim strsql
'Setup connection and recordset objects
set conn = server.createobject("adodb.connection")
conn.open strconn
set rs = server.createobject("adodb.recordset")
'Define your sql statement that will retrieve the data
strSql = "SELECT tblMemberInfo.EmpID tblMemberInfo.EmailAddress tblMemberInfo.Link_to_Homepage" & _
" FROM tblMemberInfo WHERE (((tblMemberInfo.Link_to_Homepage) LIKE '%http://%'" & "))" & _
" ORDER BY tblMemberInfo.EmpID"
'Open the Recordset object and retrieve data
rs.open strsql conn
 
'Standard Error Coding
If err.number <> 0 Then
Response.Redirect "Error.asp?number=" & err.Number & "&desc=" & Server.URLEncode(err.description)
End If
%>
<% rs.movefirst %>
<html>
<head>

<title>
Template Page</title>
</head>
<body>
<table BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="390" height="63">
<tr>
<td height="24"><font face="Verdana"><big><big><strong>Example List of people w/Their email address's and Favorite homepage links <br>These links are dynamically generated from data into the Database.</strong></big></big></font></td>
</tr>
</table>
<TABLE BORDER="1" width="80%">
<TR>
"Write out the header info
<% For Each Field In RS.Fields %>
<TH> <% If Field.Name <> "MemberID" Then
response.write Field.name
End If %> </TH>
<% Next %>
Write out the data info!
</TR>
<% Do While Not RS.EOF %>
<TR>
<% For Each Field In RS.Fields %>
<TD ALIGN=center>
<% If IsNull(Field) Then
Response.Write ""
ElseIf Field.Name = "EmpID" Then
Response.Write "<a href='http://" & Request.Servervariables("Server_Name") & "/asp/demos/Profile.asp?EmpID=" & rs("EmpID") & "&EmailAddress=" & rs("EmailAddress") & "'>" & Field.Value
ElseIf Field.Name = "EmailAddress" Then
response.write "<a href=mailto:" & field.value & ">" & Field.Value & "</a>"
ElseIf Field.Name = "Link_to_Homepage" Then
response.write "<a href='javascript:void(0);' onClick=window.open('" & field.value & "')>" & Field.Value
Else
Response.Write Field.Value
End If %>
</TD>
<% Next
RS.MoveNext %>
</TR>
<% Loop %>
</TABLE>
<% Rs.Close
Set Rs = Nothing %>
<p>&nbsp;</p>
</body>
</html>
<%
conn.close
set conn = nothing
%>

Page 2 The Profile Page that shows the complete info on the person that was chosen!

<%@ Language = "VBScript"%>
<%
response.buffer = True
On Error Resume Next
'Declare all local variables
dim conn
dim rs
dim strID
Dim strZoneName
Dim StrEmailAddress
Dim StrRowSpan
dim StrImageInfo
dim strconn
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("hyperlinkdemo.mdb")
 
'Pick values up from the url
strEmpID = request("EmpID")
strEmailAddress = request("EmailAddress")
'Set connection String and recordset objects to bring back member info from db
set conn = server.createobject("adodb.connection")
conn.open strconn
'Standard Error coding
If err.number <> 0 Then
Response.Redirect "Error.asp?number=" & err.Number & "&desc=" & Server.URLEncode(err.description)
End If
set rs = server.createobject("adodb.recordset")
strSql = "select tblMemberInfo.EmpID tblMemberInfo.EmailAddress tblMemberInfo.Link_to_Homepage" & _
" FROM tblMemberInfo" & _
" WHERE (((tblMemberInfo.EmpID)='" & strEmpID & "')" & " AND ((tblMemberInfo.EmailAddress)='" & strEmailAddress & "'))"
rs.open strsql conn
'Standard Error Coding
If err.number <> 0 Then
Response.Redirect "Error.asp?number=" & err.Number & "&desc=" & Server.URLEncode(err.description)
End If
'Sets local variables to help write out the table
strRowSpan = rs.fields.count + 1
strImageInfo = rs("path_to_image")
%>
<html>
<head>
<title>Profile Page</title>
</head>
<body>
<h1>The Profile you chose is for:<% = strEmpID %>
<form>
<TABLE BORDER="1">
<tr><td BGCOLOR="FFFFFF" rowspan="<% = StrRowSpan %>">
<%
'Determines if an image is in the database or not if so it writes out the path
If strImageInfo <> "" Then
response.write "<img src='" & strImageInfo & "'></td>"
Else
response.write "<h4>No Picture Provided</h4></td>"
End If
%>
</tr>
<%
'Writes out the info on the player based on the info in the database
Do While Not RS.EOF %>
<% For Each Field In RS.Fields %>
<tr>
<TD ALIGN="Left">
<%
response.write Field.Name & ":</td><td><input type='text' name='" & field.name & "' length='140' value='" & Field.Value & "'></TD></TR>" %>
<% Next
RS.MoveNext %>
<% Loop %>
</TABLE></form>
<p>&nbsp;</p>
</body>
</html>
<%
'Sets the objects to nothing to help clean up objects in servers memory
set rs= nothing
set conn = nothing
%>
blog comments powered by Disqus
ASP CODE ARTICLES

- ASP Forms
- ASP: The Beginning
- Getting Remote Files With ASP Continued
- Inbox and Outbox Manipulation in ASP
- Relational DropDownList Using VB.NET
- Ad Tracking URL Hits
- Use ViewState to display one record per page...
- Send Email using ASP.NET formatted in HTML
- ASP File Explorer
- ASP/XML Interview questions by Srivatsan Sri...
- Pressing RETURN won't submit the form
- This shows how you get the TEXT of a combo r...
- Group Data by Adrian Forbes
- Multiple checkbox select sample
- Multiple checkbox select with all values sam...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials