FREE tutorial,solution,RSS Feeds on Operating Systems, Programming, Web Development, Applications, Databases, Networking, Hardware, Security, SEO Free Expertsforge Membership
Join us as Moderator
Submit Article to Expertsforge.com Submit Article My Expertsforge
 
RSS Feeds, Help Help RSS Feeds
bannertop
 

ASP Tutorial: Creating Data-Driven Hyperlinks with GetString

jawahar
4/17/2005 5:15:16 PM, Views: 2572
The following tutorial describes the creation of hyperlinks to the fields displayed using Getstring

For example, I might need to know the details of a company called "Laughing Lumberjack Lager" having a unique ID which is the primary key. So I display the name of the company as a hyperlink to a page and append the ID to the link. A bit confusing, so let me explain with an example.

Consider the following hyperlink: <a href="display.asp?id=67">Laughing Lumberjack Lager</a>. If a user clicks on the hyperlnk Laughing Lumberjack Lager, he will see all the required details about the company Laughing Lumberjack Lager displayed by the page display.asp. The ASP page display.asp would contain the code to displays the details for a particular company (specified by the ID passed through the QueryString). Within the page display.asp lies a line
<% ID = Request.QueryString("id") %>
Since I now possess the ID of the company, I can use it in my SQL query to obtain the company details!

Using GetString, we can create a list of hyperlinks from a database table! To display such a hyperlink-list, we only need to make a small change to the code we looked at in Part 1 (specifically the few lines of code around the call to GetString and the SQL string).

<%
   Option Explicit
   'Create the SQL query
   Dim mySQL
   mySQL="select FAQCategoryID, Name from tblFAQCategory order by Name"
   'Create the Connection and execute the query.
   Dim objConn
   Set objConn = Server.CreateObject("ADODB.Connection")
   objConn.Open "DSN=MyDSN"
   Dim objRS
   Set objRS = objConn.Execute(mySQL)
   'Incase no records exist, have a handler to present a sweet message
   'and call the subroutine CloseConn which closes the connection.
   If objRS.eof then
      Response.Write "Sorry, No records were found.<br>"
      Call CloseConn
      Response.End
   End If
   'This part of the code creates the various hyperlinks
   'selected option for all companies.
   Response.write("<a href=""display.asp?ID=")
   Response.Write objRS.GetString(,,""">", _
                     "</a><br><a href=""display.asp?ID=", "-null-")
   Response.Write("""></a>")
   Call CloseConn   'Clean up!
   ' Sub to handle closing and cleaning up connections
   Sub CloseConn
      objRS.close
      set objRS = Nothing
      objConn.close
      Set objConn = Nothing
   End Sub
%>
Next Steps:
Add this Tutorial to:
Blink Blink del.icio.ous Del.icio.us Digg Digg
Fark Fark Furl Furl Google Google
Reddit Reddit Simpy Simpy Spurl Spurl
Technorati Technorati Windows Live Win Live Yahoo Yahoo
Rate Me!
Not Yet Rated!
Rate:
Send Private MessageSend Message
Signup / Login To View the Solution or Provide Comments
Post Comment/Solution
Comment:*
        (Link Rules) 
  Use : [bold] for <b>; [/bold] for </b>; [italic] for <i>; [/italic] for </i>; [code] & [/code] for code
 
Categories
Options
ASP RSS Feed
Most Popular Tutorial
Most Popular Solution
Top Rated
Top Contributors
Yearly
Overall
 
1. jawahar (200)
bnrtop