Batch Deletes Made Simple
This tutorial, adapted from Chapter 15 of The Joy of Dreamweaver MX, explains how to enable batch deletes via check boxes in three simple steps.
The Joy of Dreamweaver MX: Recipes for Data-Driven Web Sites is a web developer's cookbook filled with dozens of "secret" recipes that DMXers can really sink their teeth into.
For more information, visit the book's companion web site, or read a sample chapter - "Uploads Made Simple" - on UDzone.COM.
Batch Deletes Made Simple |
|
In this tutorial, you'll learn to enable batch deletes using check boxes in
three simple steps:
- Apply Dreamweaver's standard Delete Record server behavior
- Cut and paste the hidden form field, MM_recordId
- Revise the SQL DELETE statement
This tutorial is adapted from Chapter 15 of The
Joy of Dreamweaver MX: Recipes for Data-Driven Web Sites. For more
information about the book, visit the companion web site, www.newmanzone.com.
You can also read a sample chapter, "Uploads
Made Simple," here on UDzone.com.
Step 1: The Delete Record Server Behavior
This tutorial assumes you've already created an HTML form with dynamic text,
a check box, and a submit button.
NOTE: If you don't have an existing site to work with, you can
download the sample code for The Joy
of Dreamweaver MX. The page displayed in the screenshot below is links.asp.
You'll find it in the realty_asp_empty/www/adminch folder.
Let's also assume that you've created a repeat region that displays more than
one record:
The first step is to apply Dreamweaver's standard Delete Record SB. From the
Server Behaviors panel, choose Delete Record. Choose your connection and select
the table that contains the records you wish to batch-delete. Make sure that
the table's primary key column is selected in the Unique Key Column drop-down
menu, and that Numeric is checked (unless, of course, you're using a non-numeric
primary key). Leave the redirect text box empty and click OK to apply the server
behavior.
Notice that Dreamweaver inserts two hidden fields into the end of the
form: MM_delete and MM_recordId.
The first field, MM_delete, is a flag that's used
to determine whether the Delete Record code is executed. The second field, MM_recordId,
stores the value of the table's primary key column (e.g., <%=
rsLinks.Fields.Item("LinkID").Value %>).
Dreamweaver's Insert Record SB is designed to delete a single record from a
database table. We want to delete multiple records. So the next step is
to cut and paste the hidden form field attributes into
the check box.
Download
Sample Code
Author of "The Joy of Dreamweaver MX: Recipes for Data-Driven Web Sites," Paul Newman is President of BRAVE NEW WURLD, a New York web design firm. He has a BA in English and Creative Writing from Binghamton University and an MFA in Film Production from the UCLA Department of Film, Television, and Digital Media.
Paul's computer experience dates back to 1985, when he bought one of the first Apple Macintosh computers in his senior year of college. He has been building web sites since 1997, and his clients include RaikaUSA.com, VoiceoverAmerica.com, Officetek.com, and BarbaraTyson.com.
See All Postings From P.R. Newman >>