Show Region - page 16
August 14,2002
Show Region contains a set of server behaviors that allow you to show regions
of your document based on a few conditions. In our application, we'll utilize
two, to sort out the problems discussed above:
Show Region If Not First
Record
Highlight the Previous hyperlink that was generated
by the Move
to Previous Record behavior. Select Server Behaviors
> +
> Show
Region > Show Region If Not First Record, and
OK
the box that appears.
Show Region If Not Last Record
Highlight the Next hyperlink that was generated by the Move to Next Record behavior. Select Server Behaviors > + > Show
Region > Show Region If Not First
Record, and OK the box that
appears.
Now view the books.asp page in a browser, and you should see that the Previous hyperlink does not appear until you
get to the second group of records. Similarly the Next hyperlink does not appear when you get
to the last group of records.
Recordset Navigation Bar
Before we move onto another server behavior, I am going
to show you something else Dreamweaver MX can do for you. Think about how
many steps it took to implement the recordset Paging – we had to work with
four different server behaviors: Move To Previous Record, Move To Next Record, Show Region If Not First Record, and Show Region If Not Last Record.
Brace yourself...we could've
done this in one step using the Recordset Navigation
Bar object! It can be found under Insert
> Application
Objects. This object utilizes the same server behaviors we used
before, but selecting it inserts fully functional First,
Previous,
Next,
and Last
hyperlinks – instantly.
Dreamweaver MX has some other Application Objects that save us extra
steps, as we shall see later. However, I want you to be able to use the server
behaviors individually before using the additional timesaving Application
Objects, to aid your understanding – I hope you forgive me!
Now let's continue our look at the Show Region behaviors.
Show Region If Recordset
Is Empty
There may be some instances where a recordset comes up
empty meaning it has retrieved no records based on the query. I left one of
the categories empty so that I can demonstrate this server behavior for you.
If you click on the World Literature category on your master page
you will see that the detail page is empty because there are no books associated
with this category. If this were a real-world application, you would most
likely want to display a message when a query comes up empty. For example,
you might display, "Sorry, no records found. Please go back and select
another category." Without further ado, let's do that now.
Before we add the server behavior let's add the text, "Sorry,
no records found. Please go back and select another category." Add another
row above the other rows in your table. You should now have an empty first
row. Place your cursor in the second column of this row and type your message
there. Highlight the row by selecting the <tr> tag from the page status bar while your cursor is in the row. Select
Server Behaviors > + > Show
Region > Show Region If Recordset
Is Empty.
View your page live now by loading the categories3.asp page. Select the World Literature
category. You should see your message displayed because the recordset will
be empty.
There is another issue on the page that calls for the use
of another server behavior. I don't know about you but I think it looks a
bit messy having the rest of the table showing but empty when the records
come up empty. If you don't mind you can leave it, but we can easily hide
it when the recordset is empty like so:
Show Region If Recordset
Is Not Empty
Return to your document in Dreamweaver MX and highlight
the second row of the table. Select Server Behaviors > + > Show
Region > Show Region If Recordset
Is Not Empty. Repeat this process for the third row of the table. Now
if you view the page in a browser, the rest of the table should not display
when the recordset on the detail page is empty.
So far we have learned how to:
·
Create recordsets to retrieve database records
·
Display database records dynamically on our
web pages
·
Filter recordsets by parameters passed and show and hide regions based
on conditions
It would be great if we could now add a system to allow
us to update our data without having to manually go into our database to do
so – create a web application with Dreamweaver MX that will allow us to insert,
update, and delete database records.
Recordset Paging - Page 15
Dynamic Dreamweaver MX
Insert Record - Page 17
|