Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Using generic VBScript objects in ASP. Display re...
Author:
Volodymyr Kuzmyk
E-mail:
Click to e-mail author
Submitted:
4/13/2000
Version:
ASP
Compatibility:
ASP
Category:
ASP
Views:
18134
Using generic VBScript objects in ASP. Display records in HTML Table using dynamically created object DBTable.
Declarations:
'Suppose you have MSAccess database myData.mdb and want to display Employee table. 'Employee table has following fields (index begins from 0): ' 0. Emp_ID ' 1. FirstName ' 2. LastName ' 3. HomePhone ' ............ bla bla ' 6. EMail ' 'You want to be able edit employee data or send email to each employee. 'In this case Edit.asp must contain following line to get proper employee data: ' strSQL = "SELECT * FROM Employee WHERE Emp_ID=" & Request.QueryString ' and edit the data using Edit.asp's form.
Code:
'*******DEFAULT.ASP******** <% Dim oTable Dim strText Set oTable = New DBTable oTable.ConnString= "DRIVER=Microsoft Access Driver (*.mdb); DBQ=" & Server.MapPath ("myData.mdb") oTable.SQL = "SELECT * FROM Employee ORDER BY LastName" oTable.BackColor="#99FF99" oTable.BorderWidth=1 With oTable.Cols .Add 'Add first column definition .Item(0).Name="Last Name" 'Column name to be shown on the header .Item(0).Index=2 'field index in recordset .Item(0).Width=25 'Column width in % .Item(0).BackColor="#99FF99" 'Column Background color .Item(0).FontBold=True 'Column Font is bold .Item(0).FontColor="#0000FF" 'Column Font color .Item(0).HRef="Edit.asp?" 'Click on last name to edit employee data(don't forget "?") .Item(0).HRefParam=0 'with employee_id as parameter 'and so on .Add .Item(1).Name="First Name" .Item(1).Index=1 .Item(1).Width=25 .Item(1).FontItalic=True .Add .Item(2).Name="Home phone" .Item(2).Index=3 .Item(2).BackColor="#CCFFCC" .Item(2).Width=25 .Add .Item(3).Name="E-Mail" .Item(3).Index=6 .Item(3).Width=25 .Item(3).HRef="mailto:" 'you even may send an e-mail by clicking on this field .Item(3).HRefParam=6 'this is the index of EMail field in the recordset End With oTable.Show 'Generate HTML code and show table Set oTable = Nothing %> ------------------------------------------------------------------------------------------ DBClasses.asp ------------------------------------------------------------------------------------------ '***************************************************************************************** ' Copyright NCIC, 2000 ' Author: Volodymyr Kuzmyk ' Company: NCIC Consulting Group 240 W 55th St., New York, NY 10019 ' ' Questions or comments: vk@ncicny.com, vkuzmyk@aol.com '***************************************************************************************** 'Option Explicit '-------------------------------------- 'Start of Column '-------------------------------------- Class Column 'local variables to hold property values Private mvarIndex Private mvarName Private mvarVisible Private mvarFontSize Private mvarFontBold Private mvarFontItalic Private mvarFontColor Private mvarFontName Private mvarBackColor Private mvarHRef Private mvarHRefParam Private mvarWidth Private Sub Class_Initialize() Visible = True Width = 0 HRef = "" FontBold = False FontItalic = False FontSize = 3 Name = "FieldName" Index = 1 End Sub Public Property Let Width(ByVal vData) mvarWidth = vData End Property Public Property Get Width() Width = mvarWidth End Property Public Property Let HRef(ByVal vData) mvarHRef = vData End Property Public Property Get HRef() HRef = mvarHRef End Property Public Property Let HRefParam(ByVal vData) mvarHRefParam = vData End Property Public Property Get HRefParam() HRefParam = mvarHRefParam End Property Public Property Let BackColor(ByVal vData) mvarBackColor = vData End Property Public Property Get BackColor() BackColor = mvarBackColor End Property Public Property Let FontName(ByVal vData) mvarFontName = vData End Property Public Property Get FontName() FontName = mvarFontName End Property Public Property Let FontColor(ByVal vData) mvarFontColor = vData End Property Public Property Get FontColor() FontColor = mvarFontColor End Property Public Property Let FontItalic(ByVal vData) mvarFontItalic = vData End Property Public Property Get FontItalic() FontItalic = mvarFontItalic End Property Public Property Let FontBold(ByVal vData) mvarFontBold = vData End Property Public Property Get FontBold() FontBold = mvarFontBold End Property Public Property Let FontSize(ByVal vData) mvarFontSize = vData End Property Public Property Get FontSize() FontSize = mvarFontSize End Property Public Property Let Visible(ByVal vData) mvarVisible = vData End Property Public Property Get Visible() Visible = mvarVisible End Property Public Property Let Name(ByVal vData) mvarName = vData End Property Public Property Get Name() Name = mvarName End Property Public Property Let Index(ByVal vData) mvarIndex = vData End Property Public Property Get Index() Index = mvarIndex End Property End Class '------------------------ 'end of Column '------------------------ '------------------------ 'Start of Columns collection '------------------------ Class Columns 'local variable to hold collection Dim arCol Private Sub Class_Initialize() arCol = Array() End Sub Public Function Add() 'create a new object Dim objNewMember Set objNewMember = New Column 'assign object to collection Redim Preserve arCol(Count) set arCol(Count-1) = objNewMember Set objNewMember = Nothing End Function Public Property Get Item(vntIndexKey) Set Item = arCol(vntIndexKey) End Property Public Property Get Count() Count = UBound(arCol)-LBound(arCol)+1 End Property Private Sub Class_Terminate() Set arCol = Nothing End Sub End Class '------------------------ 'end of Columns collection '------------------------ '------------------------ 'Start of DBTable '------------------------ Class DBTable 'local variables to hold property values Private mvarConnString Private mvarBackColor Private mvarCaption Private mvarBorderWidth Private mvarSQL Private mvarColumns Private mvarWidth Private Sub Class_Initialize() Set Cols = New Columns BorderWidth=1 Width="100%" End Sub Private Sub Class_Terminate() Set Cols = Nothing End Sub Public Property Set Cols(vData) Set mvarColumns = vData End Property Public Property Get Cols() Set Cols = mvarColumns End Property Public Property Let SQL(vData) mvarSQL = vData End Property Public Property Get SQL() SQL = mvarSQL End Property Public Property Let Width(vData) mvarWidth = vData End Property Public Property Get Width() Width = mvarWidth End Property Public Property Let BorderWidth(vData) mvarBorderWidth = vData End Property Public Property Get BorderWidth() BorderWidth = mvarBorderWidth End Property Public Property Let Caption(vData) mvarCaption = vData End Property Public Property Get Caption() Caption = mvarCaption End Property Public Property Let BackColor(vData) mvarBackColor = vData End Property Public Property Get BackColor() BackColor = mvarBackColor End Property Public Property Let ConnString(vData) mvarConnString = vData End Property Public Property Get ConnString() ConnString = mvarConnString End Property Public Sub Show() Dim oConn 'Connection Object Dim oRS 'Recordset Object Dim arData 'Array to hold records Dim strRow 'HTML row Dim isError 'Error Set oConn = Server.CreateObject("ADODB.Connection") oConn.Open ConnString Set oRS = oConn.Execute(SQL) if oRS.eof=true then isError=true else arData = oRS.GetRows oRS.Close Set oRS = Nothing oConn.Close Set oConn = Nothing if isError then Response.Write "
" & "No records found." & "
" Exit sub end if 'Now all requested data in arData (as array) 'No more requests to the server!!! 'Start displaying table Response.Write "
" Response.Write "
" & Caption & "
" Dim j, i '--------------------------------- 'Show Table Headers using arFields' data '--------------------------------- strRow = "
" For i=0 to Cols.Count-1 If Cols.Item(i).Width>0 then strRow = strRow & "
" strRow = strRow & Cols.Item(i).Name & "
" Next strRow = strRow & "
" Response.Write strRow '-------------- 'Now Show Data '-------------- For j=0 to ubound(arData,2) 'For Each Row strRow = "
" For i=0 to Cols.Count-1 'For Each Column If Cols.Item(i).Width>0 then strRow = strRow & "
" if Cols.Item(i).FontBold = True then strRow = strRow & "
" if Cols.Item(i).FontItalic = True then strRow = strRow & "
" if isEmpty(Cols.Item(i).FontColor)= False then strRow = strRow & "
" if Cols.Item(i).HRef <> "" then strRow = strRow & "
" '---cell data---- strRow = strRow & arData(Cols.Item(i).Index,j) '---cell data---- if Cols.Item(i).HRef <> "" then strRow = strRow & "
" strRow = strRow & "
" if Cols.Item(i).FontItalic = True then strRow = strRow & "
" if Cols.Item(i).FontBold = True then strRow = strRow & "
" strRow = strRow & "
" Next strRow = strRow & "
" Response.Write strRow Next Response.Write "
" End Sub End Class '------------------------ 'End of DBTable '------------------------ '* END OF DBCLASSES***
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement