|
This example shows the use of the <VbsDbExecute> and <VbsDbFieldParameter> elements within
an Update Template (and a Delete Template).
Try to update (or delete) some products: you can see, that an Alert!! message is displayed in red when the units in stock are less than 20,
otherwise an Ok!! message is displayed in green.
To do this, a UnitsAlert function is defined in the asp page (see below the UnitsAlert function VBScript code). Such function
is invoked in each Update (or Delete) screen: this is done by the <VbsDbExecute>UnitsAlert(...)</VbsDbExecute>
statement in the Edit Template file (see below the EditTemplateWithConditionalFormattingExample.htm code).
UnitsAlert returns the html code to display the Alert!! message with a red font if the passed parameter is less
than 20, otherwise UnitsAlert returns the html code to display the Ok!! message with a green font.
The UnitsInStock field value for the record to be updated (or deleted), is passed to the UnitsAlert function:
this is done by the <VbsDbFieldParameter>UnitsInStock</VbsDbFieldParameter> statement contained in the
Edit Template file.
|
1 |
Chai
|
39
|
|
2 |
Chang
|
17
|
|
3 |
Aniseed Syrup
|
13
|
|
4 |
Chef Anton's Cajun Seasoning
|
53
|
|
5 |
Chef Anton's Gumbo Mix
|
0
|
|
|
|
This is the code implementing the example:
<!--#include file="VBSdb/inc.asp"-->
<%
VbsDbNew objVbsDb
objVbsDb( "Sql" ) = "select * from Products"
objVbsDb( "ViewNavigationButtons" ) = "first;prev;next;last;removeFilter;search;add;delete;update"
objVbsDb( "GridFields" ) = "ProductName,UnitsInStock"
objVbsDb( "EditTableName" ) = "Products"
objVbsDb( "EditKeyFields" ) = "ProductID"
objVbsDb( "EditDeleteTemplate" ) = "EditTemplateWithConditionalFormattingExample.htm"
objVbsDb( "EditDeleteTemplate" ) = "EditTemplateWithConditionalFormattingExample.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 EditUpdateTemplateExample.htm, the template file used for this example:
<TABLE cellSpacing=1 cellPadding=1 width="100%" border=1>
<TR>
<TD align=right>Product Name:</TD>
<TD colSpan=3 align=left><VbsDbFieldValue>ProductName</VbsDbFieldValue></TD>
</TR>
<TR>
<TD align=right>Quantity per Unit:</TD>
<TD><VbsDbFieldValue>QuantityPerUnit</VbsDbFieldValue></TD>
<TD align=right>Units in Stock:</TD>
<TD>
<VbsDbFieldValue>UnitsInStock</VbsDbFieldValue>
<VbsDbExecute>UnitsAlert(<VbsDbFieldParameter>UnitsInStock</VbsDbFieldParameter>)</VbsDbExecute>
</TD>
</TR>
<TR>
<TD align=right>Units on Order:</TD>
<TD><VbsDbFieldValue>UnitsOnOrder</VbsDbFieldValue></TD>
<TD align=right>Reorder Level:</TD>
<TD><VbsDbFieldValue>ReorderLevel</VbsDbFieldValue></TD>
</TR>
<TR>
<TD align=right> Discontinued:</TD>
<TD><VbsDbFieldValue>Discontinued</VbsDbFieldValue></TD>
<TD align=right>Unit Price:</TD>
<TD><VbsDbFieldValue>UnitPrice</VbsDbFieldValue></TD>
</TR>
<TR>
<TD align=center colspan=4><VbsDbInputSubmit> <VbsDbInputReset> <VbsDbInputCancel></TD>
</TR>
</TABLE>
This is the code implementing the UnitsAlert function:
'***********************************************
function UnitsAlert( strUnitsInStock )
'***********************************************
if cInt( strUnitsInStock ) < 20 then
UnitsAlert = "<font color=red>Alert!!</font>"
else
UnitsAlert = "<font color=green>Ok!!</font>"
end if
end function
|