Tips Station Asp.net Article Seo Articles
Tutorials Code Samples
›  Home
›  Mission
›  About us
›  Contact Us
›  Feedback
›  Terms & Condition
Asp Articles
IT Solutions
 
› ASP.NET

› Programming Tips

› Ajax

› Asp

› ADO.NET

› Databases

› SEO

› CSS And Designing

› Php

 
Most Viewed Articles
 
› Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

› Change theme dynamically without page refresh in ASP.NET

› Install AJAX On Machines Running Visual Studio 2005

› Creating Pretty Popups Using AJAX

› Simple ASP Image Resize Function

› SQL Server Performance Counters

› ASP.Net Interview Questions And Their Answers

› Encode Url using ASP

› Difference Between DataGrid and GridView in Asp.Net

› Select Specific Value WithIn Drop Down List Or Radio Button List

more...
 
 
Home> Asp
 
Alternating Row Colors
 

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 ASP:

 

<%
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>
<%
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
%>
</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.

This article has been taken from webdesign.org.

 
 
Vrp Technologies
 
Serversea Hosting
 
 
Latest Articles
 
› Sending SMS With PHP

› MySQL Join Tutorial

› Make An RSS Feed Using PHP

› Intro To Object: Option Variables

› Design An Online Chat Room With PHP And MySQL

› Create Tell A Friend Script With HTML & PHP

› Benchmark And Optimize PHP Script Speed

› What Kind of DBA Are You?

› SQL Server Performance Counters

› SQL Server Performance Tips

more...
 
Random Articles
 
› Search Engine Friendly Web Design - 3 Ways To Use CSS

› Displaying Data using ASP.NET 2.0 DataList

› ADO.NET Data Classes

› .NET Data Access Performance Comparison

› Design Considerations for Cross Page Post Backs in ASP.NET 2.0

› Session Object in Asp

› Change theme dynamically without page refresh in ASP.NET

› Ten Tips To Optimize Your Website

› Displaying Data using ASP.NET 2.0 GridView

› How to Send an Email in Asp.Net

more...
 
Home Mission About us Contact us Feedback Terms Conditions
2008 © Copyright TipsStation. All rights reserved.