<% Option Explicit %> <!--#include file="adovbs.inc"--> <% Response.ExpiresAbsolute = Now() - 1 %> <HTML> <HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- function DeleteProducts() { if (confirm("This will delete products! Are you sure you want to do this!?")) { document.forms[0].action = "DeleteProducts.asp"; document.forms[0].submit(); } } function UpdateCosts() { document.forms[0].action = "UpdateCosts.asp"; document.forms[0].submit(); } // --> </SCRIPT> <BODY> <% 'Open a connection to the database Dim objConn Set objConn = Server.CreateObject("ADODB.Connection") objConn.ConnectionString = "DSN=TestDB" objConn.Open 'Get the table information for products Dim objRS Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open "Products", objConn, adOpenForwardOnly, adLockReadOnly, adCmdTable 'Display the FORM and the top of the TABLE Response.Write "<FORM METHOD=POST ACTION=""DeleteProducts.asp"">" Response.Write "<TABLE BORDER=1 CELLSPACING=1>" Dim iLoop Response.Write "<TR>" Response.Write "<TH>Delete</TH>" Response.Write "<TH>Name</TH>" Response.Write "<TH>Cost</TH>" Response.Write "</TR>" Dim iCount iCount = 0 'Display the name and price of each product Do While Not objRS.EOF Response.Write "<TR>" & vbCrLf 'Create a checkbox to check for deleting, setting the checkboxes 'Value equal to the current items ProductID Response.Write "<TD ALIGN=CENTER><INPUT TYPE=CHECKBOX NAME=Delete " Response.Write "VALUE=" & CInt(objRS("ProductID")) & "></TD>" 'Display the name and cost of the product Response.Write vbCrLf & "<TD>" & objRS("Name") & "</TD>" Response.Write vbCrLf & "<TD><INPUT SIZE=10 TYPE=TEXT NAME=""" & _ iCount & ".Cost"" VALUE=""" & _ FormatCurrency(objRS("Cost"),2) & """ " & _ "STYLE=""text-align:right;"">" & vbCrLf Response.Write "<INPUT TYPE=HIDDEN NAME=""" & iCount & ".ID"" " & _ "VALUE=""" & objRS("ProductID") & """>" & vbCrLf Response.Write "</TD></TR>" & vbCrLf & vbCrLf 'Move to the next record... objRS.MoveNext 'Increment the count variable iCount = iCount + 1 Loop 'Print the end of the table, the submit button, and the 'the end of the form. Response.Write "</TABLE>" 'Clean up our ADO objects objRS.Close Set objRS = Nothing objConn.Close Set objConn = Nothing %> <P> <INPUT TYPE=BUTTON VALUE="Update Product Costs" ONCLICK="UpdateCosts();"> <P> <INPUT TYPE=BUTTON VALUE="Delete Selected Products" ONCLICK="DeleteProducts();"> <INPUT TYPE=HIDDEN NAME=Count VALUE="<%=iCount - 1 %>" </FORM> </BODY> </HTML>