We're going to follow a slightly different method for deleting a record than we did for updating a record. This time, we're going to use the Delete Record Server Behavior. Follow these steps:
Add [Delete] next to the Update link in the Table column.
Highlight the [Delete] link, and add the Go To Detail Page Server Behavior to the link, just as we did before, only this time specifying DeleteCategory.asp as the Detail Page.
Create a new blank page, and add a header such as Delete a Category.
Add a recordset similar to the one we added earlier, except name this one something like DelCat.
Make sure you filter the recordset on the URL parameter CategoryID, as we've done in Figure 20.40.
Figure 20.40: Our recordset for our delete page is similar to the update page recordset.
Next, we're going to manually create a data display and form on our delete page.
Insert a table that has two columns and two rows.
In the top row, add the table headers Category ID and Category.
Next, we're going to manually add the fields from the recordset to our page. It's easy to do, since we just have to click and drag the fields.
Expand the recordset DelCat on the Bindings tab of the Application panel.
Drag each of the fields CategoryID and Category to the appropriate second-row spot in the table, as we did in Figure 20.41.
Figure 20.41: We're manually creating a display for the delete page.
To add a Submit button to the page, click the Button icon on the Forms Insert bar. Make sure you choose Submit as the button type.
You might want to name the button Delete Record or some other more meaningful name since this is an irreversible action. If you don't already have a form on the page (which we don't at this time), Dreamweaver MX adds a form around the button for you. (Dreamweaver MX adds the form if your cursor is in the Design window when you add the button. If your cursor is in the Code window, Dreamweaver MX will not automatically add the form.)
Normally, we'd name our form, but since we're only using the button here, we're going to leave the default name of form1.
Click the Submit button to select it.
Add the Delete Record Server Behavior following the technique described earlier.
Again, as you can see in Figure 20.42, we're using the same definitions to define the data connection. Since our recordset name has changed to DelCat, we select it in the Select Record From drop-down list box.
Figure 20.42: Your Delete Record definition should resemble this one.
Click OK to add this behavior to the button. Delete Record will delete the current record once the user submits the form.
As all good delete actions should behave, ours should ask the user if they really want to pursue this process. We'll accomplish that by adding an OnClick event to the Behaviors tab in the Design panel. Since Submit is a unique button to HTML with a specific purpose, we'll find access to its events by right-clicking the button itself and choosing Edit Tag to open the Tag Editor dialog box. Expand the Events category, click OnClick, and add the following
into the Input window as we did in Figure 20.43.
Figure 20.43: The Submit button's events are hidden in the Tag Editor dialog box.
We should also give the user a way to cancel, or back out of, this delete process from the main page. We'll do that by adding another button with an OnClick method that simply jumps back to the BookCategory.asp page. Follow these steps:
Add another button, name it Cancel, and then select the button.
In the Behaviors tab, choose the Go To URL behavior to open the Go To URL dialog box, as shown in Figure 20.44.
Figure 20.44: Dreamweaver MX provides a behavior that lets us jump to a URL.
Add the BookCategory.asp page in the URL box, and click OK. You'll now see the onClick Go To URL behavior listed in the Behaviors tab when the button is selected.
Save your page as DeleteCategory.asp.
Load BookCategory.asp in your browser, and then click the Delete button. You should see a confirm window like that in Figure 20.45.
Figure 20.45: The confirmation message after clicking the Delete button
Click OK to delete the record. If you click Cancel, the record is preserved, and the BookCategory page is displayed again.