Web Templates
Web Templates  
Photoshop Layouts  
Flash Templates  
Templates Resource - Web Templates
   
 
  Sign UpPassword
Templates Resource Services Support Specials Members View Cart
 
  Photoshop Tutorials
  HTML Tutorials
  ASP Tutorials
  CSS Tutorials
  Javascript Tutorials
  PHP Tutorials
  XML Tutorials
  Flash Tutorials
  Fireworks Tutorials
  3D Studio Max Tutorials
  Cinema 4d Tutorials
  Graphics
  Website Tools
  Web Templates
  About Templates Resource
  Affiliates Program
  TR Support
  Webmaster Resources
 Columbia Tech Support

WebDesignHelper.co.uk


 

Tutorials: ASP - Active Server Pages

Alternating Row Colors

Intermediate

 

Learn how to alternate row colors from database output using ASP.

Simple enough, lets decide what this is going to do in English:

1. Connect to the database, execute the SQL query.
2. Run an IF...ELSE statement and use MOD 2 = 0 to figure whether the variable oddsevens is odd or even.
3. Display a background color of black or white, depending on whether oddsevens was odd or even.
4. Display the data.
5. Add one to oddsevens, so the next row will be an alternating color.
6. Move to the next row in the SQL query, continue the DO LOOP.

Here it is in PHP:

<%
Dim Conn
Dim SqlTemp
Dim oddsevens
oddsevens = 1
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\test.mdb")& ";"
Conn.Open
SQLTemp = "SELECT somecolumn FROM sometable"
set rstemp=Conn.execute(SQLTemp)
%>
<table><td>
<%
Do While Not rstemp.EOF
If (oddsevens MOD 2 = 0) Then
%>
<tr bgcolor=black><font color=white>
<%= rstemp.Fields("somedata").Value %>
</font>
<%
Else
%>
<tr bgcolor=white>
<%= rstemp.Fields("somedata").Value %>
<% End If %>
</tr>
<%
intNum = intNum + 1
rstemp.MoveNext
Loop
%>
</td></table>
<%
Conn.Close
Set Conn = Nothing
%>

Not as hard as it looks, is it? Simple idea, really. Just be sure to change test.mdb, somecolumn, sometable, and the two instances of somedata to match your database.

NOTE: Click here if you are having trouble
connecting to the database

 

This tutorial is provided to you by Spoono

More Tutorials
 

Active Server Pages Tutorials

AIM Screennames Viewer
This tutorial will show you how to make a script to see who has seen your AOL Instant Messenger profile.

Intermediate

Alternating Row Colors
Learn the basics of creating wonderfully abstract objects.

Intermediate

Browser Redirect
Learn how to do a Browser Redirect using the power of ASP.

Beginner

Cookies
Learn how to use cookies in ASP.

Intermediate

Counter
Learn how to make a hit counter in ASP.

Beginner

Database Connection
Learn the different ways to connect to different databases.

Intermediate

Database Insert
Learn how to insert a row into a MS Access database.

Beginner

Displaying Database
Learn a quick and easy way to display information from a database.

Beginner

Form Mail via CDONTS
Learn how to send mail using ASP and CDONTS

Intermediate

Form Mail via CDOSYS
Learn how to send mail using ASP and CDOSYS.

Intermediate

Number of Users Online
Use this code to display the number of users browsing.

Intermediate

Requests
Learn how to make use of requests.

Beginner

Sessions
Learn an alternative and effective solution to cookies in ASP using sessions.

Intermediate

String Functions
Learn the basic string functions available in ASP using VBScript

Beginner

XML Parsing
Use this nifty script to parse XML into HTML

Intermediate

Get help using .ASP here!

Get Free ASP Scripts here!

More Tutorials

Featured Web Templates

Web Template Preview 92313301

User Level:

Intermediate

Category:

Flash


Web Template Preview 92313401

User Level:

Intermediate

Category:

Flash



Web Template Preview 92313501

User Level:

Intermediate

Category:

Flash


Web Template Preview 92313601

User Level:

Intermediate

Category:

Flash


Web Template Preview 92313701

User Level:

Intermediate

Category:

Flash


Web Template Preview 92313801

User Level:

Intermediate

Category:

Flash


Web Template Preview 92314001

User Level:

Intermediate

Category:

Flash


Web Template Preview 92313901

User Level:

Intermediate

Category:

Flash


Web Template Preview 92314101

User Level:

Intermediate

Category:

Flash



Web Template Preview 92314201

User Level:

Intermediate

Category:

Flash

 

 

 

Templates Resource FAQ Services Terms of Use Site Map Support View Cart

© Copyright 2003-2008 Templates Resource