Get the list

By ServerWatch Staff (Send Email)
Posted Jun 6, 1999


Part 1 - Getting alphabetical ordered lists using a single ASP page.Stefano Lanfranconi
Part 1 - Getting alphabetical ordered lists using a single ASP page.
  A simple way to get an interactive, alphabetically ordered list of customers, employees, columnists etc. is to write some server-side VBScript code rows.
No word is spent in this article about how to set up an IIS-ASP engine, or about how to set an ODBC connection. It is assumed that readers are experienced enough to manage that sort of problems. See related documentation for further widening.

The only page we need is ListColumnists.asp

<%@ Language="VBScript" %>

<%
      'Let's start setting some useful values.

 
      vConnName = "SwynkList"

      'Change this with your own ole db or odbc
      'data connection name.

 
      vTableName = "Columnists"

      'Change this with the actual table name hosting your data.

 
      vDetailColor = "DeepSkyBlue"

      'This sets the bgcolor for table detail tags.


      vLetterCase = 1

      'This set the case (upper or lower) in which linked letters will be displayed:
      'Upper Case = 1; Lower Case = 2. 
%>

     
When called by server-side script, the following function arranges two rows of 13 letters linked to ListColumnists.asp both at the top and the bottom of the page as shown in Figure 1. The two parameters vColor and vCase match vDetailColor and vLetterCase respectively.

<%
      Function CreateAlphabetInTableRows(vColor, vCase)


           'The starting Chr() function number depends on vCase value

           if vCase = 1 then chrCode = 65 'Chr(65) = 'A'
           if vCase = 2 then chrCode = 97 'Chr(97) = 'a'
          
           'Writes the first row of letters

           Response.Write("<tr>")
                'This cycles through the first thirteen english alphabet letters.
                For k = chrCode to chrCode + 12
                     Response.Write("<td align='middle' bgcolor='" & vColor & "'>")
                     Response.Write("<a href='ListColumnists.asp?letter=" & chr(k) & "'>")
                     Response.Write("<font color='black' face='Verdana, Arial' size='2'><b>" & chr(k) & "</b>")
                     Response.Write("</font></a></td>" & chr(10))
                Next
           Response.Write("</tr>")
          
           '...and writes the second one.

           Response.Write("<tr>")
                'This cycles from 14th to 26th letter.
                For k = chrCode + 13 to chrCode + 25
                     Response.Write("<td align='middle' bgcolor='" & vColor & "'>")
                     Response.Write("<a href='ListColumnists.asp?letter=" & chr(k) & "'>")
                     Response.Write("<font color='black' face='Verdana, Arial' size='2'><b>" & chr(k) & "</b>")
                     Response.Write("</font></a></td>" & chr(10))
                Next
           Response.Write("</tr>")
     
      End Function
%>

When clicked, each letter becames the 'letter' parameter used by VBScript to compose the consequent list of columnists.


Two alphabetical table rows created by code Figure 1
 

Page 1 of 2


Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.