<%
Class caDataGrid
'private variables
private pAutoColumns, pConnStr, pSqlStr, intColCnt
Private pOutPut, pConn, pRec, x, y, pArray
'this runs when you create a reference to the caDataGrid class
Private Sub Class_Initialize()
Set pConn = server.createobject("adodb.connection")
Set pRec = server.createobject("adodb.recordset")
intColCnt = 0
pAutoColumns = True
End Sub
'Properties - all writable
Public Property Let ConnectionString(strConn)
pConnStr = strConn
End Property
Public Property Let AutoColumns(bAutoCols)
If bAutoCols = True or bAutoCols = False then
pAutoColumns = bAutoCols
End IF
End Property
Public Property Let SqlString(strSql)
pSqlStr = strSql
End Property
'Methods for our class
Public Sub AddColumn(strColName)
If intColCnt = 0 then
pOutPut = "<table width='100%' border=1
cellpadding=0 cellspacing=0>" & vbcrlf
pOutPut = pOutPut & "<tr>" & vbcrlf
End If
pOutPut = pOutPut & "<td><strong>" & strColName
& "</strong></td>" & vbcrlf
intColCnt = intColCnt + 1
End Sub
Public Sub Bind
pConn.Open pConnStr
Set pRec = pConn.Execute(pSqlStr)
If pAutoColumns = True then
'assign column names from returned recordset
pOutPut = "<table width='100%' border=1
cellpadding=0 cellspacing=0>" & vbcrlf
pOutPut = pOutPut & "<tr>" & vbcrlf
Redim pColNames(pRec.Fields.Count)
For x = 0 to pRec.Fields.Count - 1
pOutPut = pOutPut & "<td>"
& pRec.Fields(x).Name & "</td>" & vbcrlf
Next
End If
pOutPut = pOutPut & "</tr>" & vbcrlf
pArray = pRec.GetRows
For x = 0 to UBound(pArray, 2)
pOutPut = pOutPut & "<tr>" & vbcrlf
For y = 0 to UBound(pArray, 1)
pOutPut = pOutPut & "<td>" & pArray(y, x) & "</td>"
& vbcrlf
Next
pOutPut = pOutPut & "</tr>" &
vbcrlf
Next
pOutPut = pOutPut & "</table>" & vbcrlf
Response.Write pOutPut
End Sub
'this runs when we destroy our reference to caDataGrid
Private Sub Class_Terminate()
pOutPut = ""
pRec.Close
Set pRec = nothing
pconn.close
Set pConn = nothing
End Sub
End Class
%>
Creating a Datagrid Class in classic ASP
Creating the class
You might also like...
About the author
Brian O'Connell
Microsoft Certified Applications Developer with 10 years experience developing web based applications using asp, asp.net for a Local Authority in Dublin. Clings to a firm belief that a web appli...
Interested in writing for us? Find out more.
VB 6 books
-
Dynamic Web Application Development with ASP.Net (Computing)
This is the latest book from Cengage Learning on "Dynamic Web Application Development with ASP.NET...
VB 6 forum discussion
-
CorelDRAW VBA: cdrTraceLineDrawing FAILS, producing single linear path instead of Centerline trace?
by dancemanj (0 replies)
-
client/server application using activex
by beautifulheart (0 replies)
-
System Error &H8007007E. The specifed module could not be found.
by swiftsafe (5 replies)
-
Invitation to take part in an academic research study
by researchlab (0 replies)
-
Invitation to take part in an academic research study
by researchlab (0 replies)
VB 6 podcasts
-
Hanselminutes: Startup Series: Buying an Existing Small Company or Online Application
Published 8 years ago, running time 0h34m
Scott talks to Rob Walling about how he purchases small niche products and companies online and revitalizes them. He recently purchased an existing product that consisted of a 300 gig database and tens of thousands of lines of Classic ASP. How did he know it was valuable? What's next?
Comments