|[ LiB ]|
Building a set of master-detail pages is a fairly common dynamic task. Think of a catalog page on which all products are listed and each product entry contains a link to a page of detailed information about that product. Dreamweaver gives you two ways to build master-detail sets: manual and automatic. The manual method isn't all that manual (it doesn't involve any hand-coding ), and it gives you greater control over your layout and setup. But the automatic method is (as its name suggests!) much quicker. We'll look at both methods here.
In the manual method of building master-detail pages, you create the master and detail page, create recordsets, and link the two pages using dynamic hyperlinks . The details of this procedure are described next .
Create a page to be your main display page. As you should with any dynamic page, plan what information you want to display and how it should be laid out ahead of time. Also consider what you want the link to the detail set to look like. Do you want visitors to click an item's name, its picture, or some other generic link that says something like Click here for more ...? Whether it's a dynamic element or not, the link must be inside the repeating region so that it appears once for every record that gets displayed.
When you've got a plan, build the design framework for the page.
Collect a recordset of information to display, as you normally would for a catalog page, with one extra consideration: Be sure to include the column that functions as the primary key or unique identifier for each item. You'll need it to tell the detail page exactly which record to display. You don't need to display the identifier field anywhere , but it must be collected.
Repeat the same procedure for the detail page. Start by planning what needs to be displayed and how, and build your design framework. Don't forget to include a link back to the master page. Remember, this page will display only one record at a time, so there's no need for repeating regions or recordset paging controls.
Create a recordset of information to display, again being sure to include the unique identifier or primary key. It's what will connect the two pages.
Back in the master page, select the item(s) you want to link to the detail page. You need this item to link to the detail page but with a URL parameter that specifies the record to display. Because the parameter will be different for every record, it must be dynamically determined. Create the link this way:
If you examine the Link field at this point, you'll see that dynamic code is tucked in there. If you check out your link in Code view, it will look something like this:
<a href="closeup.php?id=<?php echo $row_Recordset1['id']; ?>"> click for close-up</a>
<a href="closeup.cfm?id=<cfoutput>#Recordset1.id#</cfoutput>"> click for close-up</a>
<a href="closeup.aspx?id=<%# DataSet1.FieldValue("id", Container) %>">click for close up</a>
This is the standard code for a link with a URL parameter:
But server-side code has been inserted in place of the parameter value.
Now that the master page is passing a parameter, the detail page needs to make use of it. In the detail page, open the recordset for editing (find it in the Server Behaviors panel's list of behaviors, and double-click it). In the Recordset dialog box, set the Filter options to filter the unique identifier field based on the URL parameter (see Figure 23.6). Because you're filtering based on a unique identifier, this recordset will collect only one record.
That's it! One page passes a parameter, the other receives it, and the parameter is dynamically generated.
In this exercise, you'll work with an alternative version of the Antiques Barn catalog page, which is template-based and that uses master and detail pages. Before doing this exercise, you should have completed Exercise 23.1, which defines a template for the Antiques Barn site and creates the catalog page.
The advantage of manually building master-detail page sets is that you can determine your layout options ahead of time and then fill in the dynamic blanks. The Master-Detail Page Set object, on the other hand, builds the layout for youalthough you can change that layout after the fact. But all the dynamic linking and even recordset paging are built for you with a few mouse clicks, so it's a very quick way to work.
The Master-Detail Page Set Object is not available for ASP.NET. ASP.NET uses a separate application object called a DataGrid that presents data and provides links to detail pages you create. For an explanation of the DataGrid, see Chapter 26, "Working Smart with ASP.NET."
To use the Master-Detail object, do this:
Master page fields The top portion of the dialog box determines what will be displayed in the master page. The master page will be built with a dynamic table displaying all fields listed here, in the order they're listed. Generally, you won't want to display all information in the master page. Remove from the top list any fields you don't want to display there. Also rearrange the list to suit your display needs.
Link to detail from You can also determine which item in the master page should function as a link to the detail page. Do you want the user to click the item's name to access the detail page? If so, choose that field from the Link to detail from menu.
Pass unique key You need to specify which field is the unique identifier key that will be passed from master to detail to determine what is displayed in that page. Choose the unique identifier field from the Pass unique key menu.
Also choose how many records at a time to display on the master page. Dreamweaver will insert recordset paging controls as needed.
Detail page name and fields In the bottom portion of the dialog box, you set the detail page options. Browse to select the blank detail page you created earlier. Adjust the list of fields to include only those that the detail page should show, in the order you want them shown. The detail page, like the master page, will be built with a dynamic table.
You can't use template child pages as the blank master and detail pages, but you can apply templates after the fact. Create your master-detail set using blank pages that aren't child pages of any template when Dreamweaver has finished. Then apply the template to the pages.
|[ LiB ]|