CRecordEdit v. 2.0
creates an HTML form given an ADO recordset. Uses different controls (textbox, checkbox, textarea) for different datatypes. Determines maxlength property based on datatype. Keeps some useful info in hidden fields.
Original Author: Neil McGuigan
Inputs
Add your own HTML and JavaScript to sections of the form:
.moreTblTags
.moreCaptionTags
.moreCellTags
.moreRowTags
Other:
.uniqueField - defaults to 0. change if needed.
.print(rs) - prints one record from the recordset.
Assumptions
Tested on all JET/ADO datatypes. Extensive SQL server testing coming soon. Should work though.
There are some hidden fields with no value that you can update with JS if you like (example 'selected field').
You should use cascading style sheets to format the form.
NS & IE event management in next version.
Returns
uses response.write to output nicely formatted HTML (with tabs and linefeeds).
Side Affects
Writes query string to a hidden field if you don't use a view.
Does not correctly determine maxlength for numeric types (except short int, and byte).
API Declarations
Copyright (C) 2001, Neil McGuigan. All rights reserved. This software is licenced.
Code
<%
'TO DO:
' cross-browser event handling (caption onclick, field on change)
'shouldn't use HTML tags for formatting, use CSS
'verify with all SQL Server types.
'add 'goto hyperlink' and 'sendmail' icons if field contains (only) a url
'fix maxlength. shows number of bits for numbers.
' end to do
class CRecordEdit
public moreTblTags
public moreRowTags
public moreCaptionTags
public moreCellTags
private m_iPKFld
public property let uniqueField(byval p)
m_iPKFld=uniqueField
end property
private sub class_initialize()
m_iPKFld=0
end sub
public sub print(byref rs)
with response
.write " .write " " & moreTblTags
.write ">" & vbCR
dim fld
for each fld in rs.fields
.write vbTab & " .write " " & moreRowTags
.write ">"
.write " select case fld.type
case 3,17,2,131,5,6,4,130,129,202,200,72,7,135,203,201
.write " onClick=""" & fld.name & ".focus();"""
case 11 : .write " onClick=""" & fld.name & ".checked=!" & fld.name & ".checked;""" 'boolean
end select
.write " " & moreCaptionTags
.write ">"
.write fld.name
.write ""
.write "' .write " " & moreCellTags
.write ">"
call showControl(fld)
.write ""
.write "" & vbCR
next
.write ""
.write vbCR & ""
.write vbCR & ""
.write vbCR & ""
.write vbCR & ""
.write vbCR & ""
.write vbCR & ""
end with
end sub
private sub showControl(byref fld)
dim name,val,maxLength,width,ftype
name=fld.name
val=fld.value
maxLength=fld.definedSize
width=""
ftype=fld.type
'took out widths, use CSS
select case ftype
case 7,135 'dates
maxLength=22
' width=21
case 3,4,5,6
maxLength=99 'should figure this out actually
case 2 'adSmallInt (-32,000)
maxLength=7
' width=7
case 72 'GUID
maxLength=38
' width=43
case 17 'byte
maxlength=3
' width=3
end select
select case ftype
case 3,17,2,131,5,6,4,130,129,202,200,72,7,135 'regular text
with response
.write " .write " type=""text"""
.write " name=""" & name & """"
.write " value=""" & val & """"
if len(maxLength)>0 then .write " maxlength=""" & maxLength & """"
' if len(width)>0 then .write " size=""" & width & """"
.write " onFocus=""this.select();"""
.write " " & moreCellTags
.write ">"
end with
case 203,201 'memo
with response
.write " .write " name=""" & name & """"
.write " rows=""4"""
.write " cols=""40"""
.write " onFocus=""this.select();"""
.write " " & moreCellTags
.write ">"
.write val
.write ""
end with
case 11 'boolean
with response
.write " .write " type=""checkBox"""
.write " name=""" & name & """"
.write " value=""true"""
if val then .write " checked "
.write moreCellTags
.write ">"
end with
case else
response.write "<binary>"
end select
with response
.write vbCR & vbTab & ""
.write vbCR & vbTab & ""
end with
end sub
end class
%>
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.