Suppressing the Navigation Bar

As always, before you start coding, you should spell out exactly what it is you are trying to accomplish. You want to show the Recordset Navigation Bar if the number of tours displayed on the page is greater than five. Remember the page is set to show only five records at a time. However, if there are five or fewer, then the Recordset Navigation Bar can't be activated.

Now, the entire Recordset Navigation Bar is stored in a self-enclosed table. So what you want to do is show that table only when the number of records is greater than five (that is, six or more). As usual, the ASP and ColdFusion code are different, but they both use the same concept.

  1. Still in tour_detail.asp, using split view and the tag selector, select the table containing the Recordset Navigation Bar.

    You have selected the entire table in both design and code views. You'll need to work in code view in the next step, but you have to isolate the table, because you'll need to add code above and below it to cause it to show conditionally. Here is a case where split view simplifies finding an element buried in code.

    Or as an option, you can add a few extra lines of white space above and below the table to help set it off.

    graphics/12fig13.gif

  2. In code view, just before the table begins, enter the opening half of the script that controls the visibility of the table based on the number of records.

    In ASP:

    <% If rs_tourDetail_total > 5 Then %>
    

    In ColdFusion:

    <cfif rs_tourDetail.recordcount gt 5>
    

    When you create a recordset, not only is the data in the recordset itself stored in memory on the server, so too is some basic information about that data. One piece of information available to ColdFusion and ASP is the record count, or number of records retrieved by the query.

    In this script, you are telling the server that if the recordcount is greater than five (the number of records you can show onscreen at any given time), then execute whatever comes after this line. What comes after it is the table that contains the Recordset Navigation Bar. If the number of recordsets is less than five (so that the if statement evaluates to false, then the script jumps ahead to the closing of the if structure (you haven't created the closing just yet) and continues. In other words, if the number of recordsets is less than five, the table that contains the Recordet Navigation Bar does not appear. This flexible structure is convenient, because no matter what happens in the databaseif new tours are added or removedthe Recordset Navigation Bar will be available if and only if it is needed.

    Now that you understand the big picture, let's address the specifics of the code itself. Both ASP and ColdFusion have a RecordCount property, which you can retrieve by typing queryname.recordcount. That's exactly how the ColdFusion code here works. The ASP code is slightly different. An earlier server behavior you applied created a new variable called rs_tourDetail_total and set it to equal rs_tourDetail.recordcount. Since that variable exists, we use that instead.

    graphics/12inf07.gif

  3. After the closing </table> tag of the table you highlighted in step 6, close the if block you opened in the preceding step.

    In ASP:

    <% End If %>
    

    In ColdFusion:

    </cfif>
    

    This is the outer boundary of the if block. If the opening line evaluates to false, ASP or ColdFusion looks for the closing of the block, so that it knows where to pick up again.

    If you were to test the page at this point, you will see that the Recordset Navigation Bar is suppressed. If you want to be extra careful, you can comment out the second SQL statement and remove the comment from the first SQL statement and test the page unfiltered. You should see all of the tours listed, and the Recordset Navigation Bar should help you move back and forth through the tours. If you do test both ways, be sure to comment the first line of SQL back out and reactivate the second line of SQL.

    graphics/12inf08.gif

  4. Save and close tour_detail.asp.



     
    ASPTreeView.com
     
    Evaluation has ВШЙїЦНЧРєіexpired.
    Info...