Browse DevX
Sign up for e-mail newsletters from DevX


Use Dreamweaver MX Server Behaviors to Automate Dynamic Data Operations : Page 3

Dreamweaver MX makes creating data-driven Web sites easy enough for even Web development novices.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Using Server Behaviors—a Simple Example
Figure 3: By default, a page displays only one record.
This example uses the Northwind database (you can use any database as long as you're familiar with the structure) that you copied to the DreamweaverSampleFiles folder. Create a recordset object and populate it with the FirstName and LastName fields from the Employees table. To add dynamic fields to a page, drag the fields to the Design View window from the Bindings tab in the Application panel. Or, click the Server Behaviors tab, click the + symbol and choose Dynamic Text. Then, select the appropriate field from the list and click OK. Be sure to insert a space character between the two fields. Name the page employees.asp.

By default, the page will display only a single row of data. For example, the script shown in Figure 3 displays only one record—in this case, it's the record for Nancy Davolio.

Tip: Click the Live Data View tool to display data in the Design View window.

To display multiple records, you must repeat the behavior that displays the single record using what's known as the Repeat Region behavior. The Repeat Region behavior adds a looping structure to the code that retrieves the records. Here's the procedure to add a Repeat Region behavior to the script shown in Figure 3:

  1. Click the Server Behaviors tab.
  2. Select the dynamic field statements—the text fields you added during the above drop and drag task. To do so, simply highlight both fields in the Design View window.
  3. Click the + symbol and then choose Repeat Region from the resulting submenu. Enter 5 in the The Records at a Time control, and then click OK in response to the Repeat Region dialog box (see Figure 4). The Records at a Time option determines how many records the page displays at one time. Dreamweaver MX adds the appropriate participant to the page. The behavior also reset the Repeat1_numRows = 0 value to display five records per page. Scroll up to see the change in the Code View window.
  4. Position the insertion point after the LastName field in the Design View window and press Return to add a line break between each employee record.
  5. Click the Live Data View tool so you can see the results in the Design window (see Figure 5).
Figure 4: Enter 5 in the Repeat Region dialog box.

Figure 5: The sample page after adding a Repeat Region behavior.
Figure 6: Insert a link to display additional records.
After adding the Repeat Region behavior, the page displays five records rather than one. However, that's not all the records available in the database. Without further modifications, the user has no way of knowing that there are more records. To display any remaining records, you must add a Recordset Paging behavior. This behavior lets users move forward and backward through the data—in this case, five records at a time. To add the Paging behavior:
  1. Position the insertion point below the Repeat Region fields in the Design View window.
  2. In the Server Behaviors tab, click the + symbol.
  3. Choose Recordset Paging, and then select Move To Next Record from the resulting submenu. Doing so adds the tag (see Figure 6). Click the Live Data View tool to display a link below the displayed records in Design View. You'll have to open the page in a browser to see the link actually work.
Open the sample employees.asp page in your browser. As expected, the first page displays the first five employee names, and clicking the Next link displays the remaining records. There are only nine records so the link actually displays the last four records. If you click the Next link again, nothing changes. That's because there are no more records to display, but your user may not know that. You can add the Show Region behavior to share information of this sort with the user. For example, to add a Show Region behavior that tells the user there are no more records in the recordset to our sample page, follow this procedure:

  1. Add the text you want displayed when there are no more records—we typed in "There are no more records to display" in the Design View window below the Next link.
  2. Select the text.
  3. Click the + symbol in the Server Behaviors tab.
  4. Choose Show Region from the menu.
  5. Select Show Region If Last Record from the resulting submenu.
  6. The Show Region If Last Record should display the rstEmployees recordset object, so click OK.
  7. Dreamweaver MX encloses the text in an If statement (see Figure 7) that determines whether or not the text is displayed. To see the actual results, open employees.asp in a browser and click the Next button (see Figure 8).
Figure 7: This behavior adds an If statement to the page.
Figure 8: Now the user knows there are no more records.
More Options, Less Work
The end result of adding these behaviors is a script that's over 300 lines long, because Dreamweaver MX inserts all the paging options by default (even if they're not required). The generated script might not be the most efficient code possible, and perhaps you'd make different choices if you wrote the script yourself. However, you didn't have to write it, and that's the whole point. You needed no scripting language expertise and little time to create this page; simple point-and-click operations sufficed to have Dreamweaver MX generate the script. DreamWeaver MX's script-generation capabilities highlight an increasingly important development trend, where developers make smart choices, but smart development environments do the grunt work of writing the code. You no longer need to be an expert at several scripting languages to build data-driven Web pages—you just need Dreamweaver MX.

Susan Sales Harkins is an independent consultant with an expertise in Access. Her latest book, SQL: Access to SQL Server, was released in January 2002.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date