coret | kepret

asal coret, kepretes

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 !!

Advertisements

September 12, 2008 - Posted by | ASP, Tutorial | , ,

1 Comment »

  1. Good research and reporting. Did you do any of the reporting yourself or are you consolidating what you read in other sources into your own synopsis? Click http://link.mx/hool08200

    Comment by hettiebaker59472 | April 8, 2016 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: