Simple Alternate Row Color dengan ASP
Tulisan ini sebenarnya masih berhubungan dengan tulisan saya sebelum ini tentang membuat alternate row color dengan PHP. Pada tulisan kali ini saya coba membahas tentang membuat alternate row color sederhana dengan ASP.
Untuk stylesheetnya silahkan dilihat di sini. Untuk database bisa menggunakan MS Access atau MS SQL Server atau Database yang lainnya. Pada tulisan ini, database yang saya gunakan adalah MS SQL Server dengan struktur table yang sama dengan posting saya sebelumnya.
<%
Option Explicit
On Error Resume Next
Dim ConnString
Dim oConn
Dim RecSet
Dim strQuery
Dim strRowClass
Dim intNomor
Set oConn = Server.CreateObject("ADODB.Connection")
'Koneksi ke SQL Server 2000
ConnString = "Provider=SQLOLEDB; Datasource=localhost; uid=test; password=test;
Database=employer"
oConn.Open ConnString
'Recordset
Set RecSet = Server.CreateObject("ADODB.Recordset")
'Query database
strQuery = "SELECT * FROM tbl_employer ORDER BY id"
RecSet.Open strQuery, oConn
Response.Write "<table width=""100%"" cellpadding=""0"" cellspacing=""1"" border=""0"">"
& VbCrlf
Response.Write "<tr>" & VbCrlf
Response.Write "<th>No</th>" & VbCrlf
Response.Write "<th>Nama</th>" & VbCrlf
Response.Write "<th>Tgl Lahir</th>" & VbCrlf
Response.Write "<th>Alamat</th>" & VbCrlf
Response.Write "<th>Kota</th>" & VbCrlf
Response.Write "<th>Propinsi</th>" & VbCrlf
Response.Write "<th>Negara</th>" & VbCrlf
Response.Write "<th>Departemen</th>" & VbCrlf
Response.Write "</tr>" & VbCrlf
If Not RecSet.EOF Then
While Not RecSet.EOF
intNomor = intNomor + 1
If intNomor Mod 2 <> 0 Then
strRowClass = "ganjil"
Else
strRowClass = "genap"
End If
Response.Write "<tr class=""" & strRowClass & """>" & VbCrlf
Response.Write "<td>" & intNomor . "</td>" & VbCrlf
Response.Write "<td>" & RecSet("employer_name") & "</td>" & VbCrlf
Response.Write "<td>" & Day(RecSet("birth_date")) & "-"
& Month(RecSet("birth_date")) & "-" & Year(RecSet("birth_date")) & "</td>" & VbCrlf
' Alternatif untuk membuat format waktu
' Response.Write "<td>" & FormatDateTime(DateValue(RecSet("birth_date")),
VbShortDate) & "</td>" & VbCrlf
Response.Write "<td>" & RecSet("address") & "</td>" & VbCrlf
Response.Write "<td>" & RecSet("city") & "</td>" & VbCrlf
Response.Write "<td>" & RecSet("states") & "</td>" & VbCrlf
Response.Write "<td>" & RecSet("country") & "</td>" & VbCrlf
Response.Write "<td>" & RecSet("department") & "</td>" & VbCrlf
Response.Write "</tr>" & VbCrlf
RecSet.MoveNext
Loop
Else
Response.Write "<tr><td colspan=""8"">Record masih kosong!</td></tr>" & VbCrlf
End If
Response.Write "</table>" & VbCrlf
%>
Good Luck !!
-
Archives
- September 2008 (2)
- October 2007 (1)
-
Categories
-
RSS
Entries RSS
Comments RSS