|
This example shows the use of the <VbsDbExecute> and <VbsDbFieldParameter> elements within
the Grid template.
As you can see, the UnitsInStock field value is displayed in red when the units in stock are less than 20,
otherwise it is displayed in green.
To do this, a FormattedUnits function is defined in the asp page (see below the FormattedUnits function VBScript code). Such function
is invoked for each Grid row: this is done by the <VbsDbExecute>FormattedUnits(...)</VbsDbExecute>
statement in the Grid template file (see below the GridTemplateWithConditionalFormattingExample.htm code).
FormattedUnits returns the html code to display the passed parameter with a red font if the passed parameter is less
than 20, otherwise FormattedUnits returns the html code to display the passed parameter with a green font.
Each time the FormattedUnits function is invoked, the current record UnitsInStock field value is passed to the FormattedUnits function:
this is done by the <VbsDbFieldParameter>UnitsInStock</VbsDbFieldParameter> statement contained in the Grid template
file.
| Product Name: |
Chai |
| Quantity per Unit: |
10 boxes x 20 bags |
Units in Stock: |
39 |
Units on Order: |
0 |
| Reorder Level: |
10 |
Discontinued: |
No |
Unit Price: |
18 |
|
| Product Name: |
Chang |
| Quantity per Unit: |
24 - 12 oz bottles |
Units in Stock: |
17 |
Units on Order: |
40 |
| Reorder Level: |
25 |
Discontinued: |
No |
Unit Price: |
19 |
|
| Product Name: |
Aniseed Syrup |
| Quantity per Unit: |
12 - 550 ml bottles |
Units in Stock: |
13 |
Units on Order: |
70 |
| Reorder Level: |
25 |
Discontinued: |
No |
Unit Price: |
10 |
|
| Product Name: |
Chef Anton's Cajun Seasoning |
| Quantity per Unit: |
48 - 6 oz jars |
Units in Stock: |
53 |
Units on Order: |
0 |
| Reorder Level: |
0 |
Discontinued: |
No |
Unit Price: |
22 |
|
| Product Name: |
Chef Anton's Gumbo Mix |
| Quantity per Unit: |
36 boxes |
Units in Stock: |
0 |
Units on Order: |
0 |
| Reorder Level: |
0 |
Discontinued: |
Yes |
Unit Price: |
21.35 |
|
|
This is the code implementing the example:
<!--#include file="VBSdb/inc.asp"-->
<%
VbsDbNew objVbsDb
objVbsDb( "MdbPath" ) = "data/nwind.mdb"
objVbsDb( "Sql" ) = "select * from Products"
objVbsDb( "ViewMode" ) = "Grid"
objVbsDb( "GridTemplate" ) = "GridTemplateWithConditionalFormattingExample.htm"
VbsDb objVbsDb
%>
This demonstrative program connects to
Nwind.mdb, the well known Microsoft Access sample database: the names of companies,
products, people,
characters, and/or data mentioned herein are fictious and are in no way
intended to represent any real individual, company, product, or event.
To download a copy of Nwind.mdb, please visit
Microsoft's site.
This is the html code for GridTemplateExample.htm, the template file used for this example:
<VbsDbGridRow>
<TABLE cellSpacing=1 cellPadding=1 width="100%" border=1>
<TR>
<TD align=right>Product Name:</TD>
<TD colSpan=5 align=left><VbsDbFieldValue>ProductName</VbsDbFieldValue></TD>
</TR>
<TR>
<TD width=130 align=right>Quantity per Unit:</TD>
<TD width=150><VbsDbFieldValue>QuantityPerUnit</VbsDbFieldValue></TD>
<TD width=110 align=right>Units in Stock:</TD>
<TD width=30 align=center>
<VbsDbExecute>FormattedUnits(<VbsDbFieldParameter>UnitsInStock</VbsDbFieldParameter>)</VbsDbExecute>
</TD>
<TD width=100 align=right>Units on Order:</TD>
<TD width=40 align=right><VbsDbFieldValue>UnitsOnOrder</VbsDbFieldValue></TD>
</TR>
<TR>
<TD align=right>Reorder Level:</TD>
<TD><VbsDbFieldValue>ReorderLevel</VbsDbFieldValue></TD>
<TD align=right>Discontinued:</TD>
<TD align=center><VbsDbFieldValue>Discontinued</VbsDbFieldValue></TD>
<TD align=right>Unit Price:</TD>
<TD align=right><VbsDbFieldValue>UnitPrice</VbsDbFieldValue></TD>
</TR>
</TABLE>
</VbsDbGridRow>
This is the code implementing the FormattedUnits function:
'***********************************************
function FormattedUnits( strUnitsInStock )
'***********************************************
if cInt( strUnitsInStock ) < 20 then
FormattedUnits = "<font color=red>" & strUnitsInStock & "</font>"
else
FormattedUnits = "<font color=green>" & strUnitsInStock & "</font>"
end if
end function
|