Figure 8
Figure 8 Setting Up the Images
' The title of the generic page
sTitle = "Authors Display"
' The page to post to (this ASP)
sFormAction = "View_Authors.asp"
' The javascript function to execute on row click
sOnRowClick_Primary = "Edit();"
' The image to use on the row click
sRowImageSource_Primary = "Edit.gif"
' The javascript function to execute on row click
sOnRowClick_Secondary= "Browse();"
' The image to use on the row click
sRowImageSource_Secondary = "Browse.gif"
Figure 9 The Client-side Onclick Event Handles
<script LANGUAGE="javascript">
<!--
//
// ***BEGIN GenericDisplayTool***
// Variable for the Row's Key Value
//
var vRowKeyValue;
//
// ***END GenericDisplayTool***
//
function Edit()
{
alert('Put code here to go edit this record, using the primary key = ' +
vRowKeyValue);
}
function Browse()
{
alert('Put code here to go view this record, using the primary key = ' +
vRowKeyValue);
}
//
// ***BEGIN GenericDisplayTool***
// Set the Row's Key Value
//
function SetRowKeyValue(vKeyValue)
{
vRowKeyValue = vKeyValue;
}
//
// ***END GenericDisplayTool***
//
//-->
</script>
Figure 10 Opening a Connection
'
' Set the parameters and get a recordset
'
sProcName = "prAPP_Get_Authors"
Set oCn = CreateObject("ADODB.Connection")
With oCn
.Provider = gsProvider
.CursorLocation = adUseClient
.ConnectionTimeout = 15
.IsolationLevel = adXactReadUncommitted
.Open gsConnectionString, sUserID, sPassword
End With
Set oCmd = CreateObject("ADODB.Command")
With oCmd
Set .ActiveConnection = oCn
.CommandTimeout = 30
.CommandType = adCmdStoredProc
.CommandText = sProcName
End With
Set oRs = CreateObject("ADODB.Recordset")
With oRs
Set .Source = oCmd
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockReadOnly
.Open
.ActiveConnection = Nothing
CloseObject oCn
End With
Figure 11 Sorting and Paging the Data
If Not oRs.EOF Then
'
' Manage the Sorting aspects
'
' If it is a 2D array ...
If IsArray(vSortOrder, 2) Then
Set oRs = SortRecordset(oRs, vSortOrder)
End If
'
' Manage the Paging aspects
'
EstablishPaging oRs, lPageSize, lPageNumber
'
' Get the data, but only get the specified number of records
'
vData = oRs.GetRows(lPageSize)
vRs(geBL_RSArray_Data) = vData
End If
Figure 12 Setting the Field-level Metadata
'
' Get the Field Level metadata
'
vFieldMetaData = GetFieldMetaData(oRs)
' Set captions
vFieldMetaData(geBL_Author_SSN)(geBL_FieldProperty_Caption) = "SSN"
vFieldMetaData(geBL_Author_FirstName)(geBL_FieldProperty_Caption) _
= "First Name"
vFieldMetaData(geBL_Author_LastName)(geBL_FieldProperty_Caption) _
= "Last Name"
vFieldMetaData(geBL_Author_Address)(geBL_FieldProperty_Caption) _
= "Address"
vFieldMetaData(geBL_Author_City)(geBL_FieldProperty_Caption) = "City"
vFieldMetaData(geBL_Author_State)(geBL_FieldProperty_Caption) = "State"
vFieldMetaData(geBL_Author_Zip)(geBL_FieldProperty_Caption) = "Zip Code"
vFieldMetaData(geBL_Author_Contract)(geBL_FieldProperty_Caption) _
= "Contract"
' Set visibility
vFieldMetaData(geBL_Author_SSN)(geBL_FieldProperty_Visible) = True
vFieldMetaData(geBL_Author_FirstName)(geBL_FieldProperty_Visible) = True
vFieldMetaData(geBL_Author_LastName)(geBL_FieldProperty_Visible) = True
vFieldMetaData(geBL_Author_Address)(geBL_FieldProperty_Visible) = False
vFieldMetaData(geBL_Author_City)(geBL_FieldProperty_Visible) = True
vFieldMetaData(geBL_Author_State)(geBL_FieldProperty_Visible) = True
vFieldMetaData(geBL_Author_Zip)(geBL_FieldProperty_Visible) = False
vFieldMetaData(geBL_Author_Contract)(geBL_FieldProperty_Visible) = False
' Set primary key
vFieldMetaData(geBL_Author_SSN)(geBL_FieldProperty_PrimaryKey) = True
vRs(geBL_RSArray_FieldMetaData) = vFieldMetaData
Figure 13 Setting the Recordset-level Metadata
'
' Get the Recordset Level metadata
'
With oRs
ReDim vRecordsetMetaData(0 To 2)
vRecordsetMetaData(geBL_RecordsetProperty_RecordCount) _
= oRs.RecordCount
vRecordsetMetaData(geBL_RecordsetProperty_PageCount) _
= PageCount(oRs.RecordCount, lPageSize)
vRecordsetMetaData(geBL_RecordsetProperty_PageNumber) = lPageNumber
End With
vRs(geBL_RSArray_RecordsetMetaData) = vRecordsetMetaData
GetRecords = vRs
Figure 15 Getting the Data
<%
'
' Data Retrieval section
'
vData = vRSArray(geBL_RSArray_Data)
vFieldMetaData = vRSArray(geBL_RSArray_FieldMetaData)
vRSMetaData = vRSArray(geBL_RSArray_RecordsetMetaData)
on error resume next
bDataExists = UBound(vData, 2)
bDataExists = CBool(err = 0)
if Not bDataExists then
lRecordCount = 0
lPageCount = 0
else
lRecordCount = vRSMetaData(geBL_RecordsetProperty_RecordCount)
lPageCount = vRSMetaData(geBL_RecordsetProperty_PageCount)
lCurrentPage = vRSMetaData(geBL_RecordsetProperty_PageNumber)
end if
on error goto 0
if Len(lLongestFieldLength) = 0 then
' Make the default length 30 characters.
lLongestFieldLength = 30
end if
%>