DreamweaverFAQ.com
Search the site!Search DWfaq.com | Print This PagePrinter Friendly Page
Current: Default | Default: The Roubaix Blues


DreamweaverFAQ.com » Tutorials » Dynamic » Multiple Repeat Regions On The Same Page


Multiple Repeat Regions on the Same Page

Step One: Creating your recordset

After you have set up your mock database and created a local dsn connection to the database:

  1. Open a new document in UltraDev and save it as: MultipleRepeat.asp

  2. Open the Server Behaviors panel: Window» Server Behaviors
    1. Click the Data Bindings tab. (In Dreamweaver MX it is just plain Bindings.)

    2. Click the "plus" button to add a new "Recordset(Query)."




    3. For this tutorial, you can use the "simple" view.

    4. Name your recordset: rsMultiRepeat*
      *it is a good idea to name each of your recordsets with a prefix of "rs" (recordset) so that you can easily identify them in code view.

    5. Select your Connection.

    6. Select your Table to retrieve the data. For this tutorial, I have selected the table "tblMembers"**
      **It's a good idea to label all your tables with a common prefix such as "tbl" so that you can easily find them in code view.

    7. For this tutorial, I have used the default selection of "all" columns for simplicity. And then sorted the data ascending by the member's first name with the column "M_FirstName".




    8. Press OK to create the recordset.

 

Step Two: Inserting two basic Repeat Regions

 

Inserting the first repeat region

You will now use the rsMultiRepeat recordset to create the first Repeat Region. This repeat region will be applied to a <p> tag containing the dynamic data of the site's members first names:

  1. In your Data Bindings panel, click the "plus" sign next to the rsMultiRepeat recordset data source to view the available columns in your database.

  2. Select the data source "M_FirstName" and insert it on your page by either clicking "Insert" or drag the data source onto your page.




  3. Save the page and preview it in your browser or with the UltraDev Live Data View. You should now see the first First Name in your database as it would appear alphabetically.

  4. Creating the first Repeat Region: Click your cursor in the newly inserted dynamic data on your page, "rsMultiRepeat.M_FirstName", and then click its corresponding <p> tag in the quick tag selector in the lower left portion of your window so that you can apply the repeat region to the <p> tag.




  5. Click the "plus" sign in the Server Behaviors tab and select the "Repeat Region" server behavior. Make sure that the rsMultiRepeat recordset is selected and "show all records" is marked. Press OK.




  6. Save the page and preview it in your browser or with the UltraDev Live Data View. You should now see all the First Names displayed on your page alphabetically.

 

Inserting the second repeat region

Now that you have your first repeat region displaying all of the member's first names alphabetically, you will now add a second repeat region displaying the exact same information, but further down the page. While this may not seem practical, I am only using this as an example. A more practical use will follow in Step Three.

Again, you will apply the repeat region to the <p> tag containing the dynamic data of all the site's members first names:

  1. Repeat steps one through three from above; do not add the second repeat region just yet.

  2. After you have inserted the second instance of the "rsMultiRepeat.M_FirstName" dynamic data on the page, preview the page in your browser or with the UltraDev Live Data View. You should not have been able to view the page and received the following error:
    ADODB.Field (0x800A0BCD)
    Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
    Simply put, this error means that there is no more data to display. Why? Because the first repeat region you applied on the page already looped through all the data in the database and has no more information to display on the page since it was set to show all the available data.

  3. In order to correct this error, you will have to hand code one simple line of code to tell the server to go back to the beginning of the data so that you can use it again. Find the following lines of Repeat Region code just after the first <p> tag with the first repeat region containing the M_FirstName data; your page should have the following code:

    <%
    <p><%=(rsMultiRepeat.Fields.Item("M_FirstName").Value)%></p>
    Repeat1__index=Repeat1__index+1
    Repeat1__numRows=Repeat1__numRows-1
    rsMultiRepeat.MoveNext()
    Wend
    %>

    and add the following line of code just after the "Wend" line: rsMultiRepeat.MoveFirst()

    <%
    <p><%=(rsMultiRepeat.Fields.Item("M_FirstName").Value)%></p>
    Repeat1__index=Repeat1__index+1
    Repeat1__numRows=Repeat1__numRows-1
    rsMultiRepeat.MoveNext()
    Wend
    rsMultiRepeat.MoveFirst()
    %>

  4. Take a look at the statement you just added, rsMultiRepeat.MoveFirst():
    1. rsMultiRepeat references the recordset rsMultiRepeat on your page.

    2. MoveFirst() is telling the server: "Go back to the first record in the rsMultiRepeat recordset so I can use all the data again."

  5. Now that you've added that line to your code, save the page and preview it in your browser or with the UltraDev Live Data View. The error no longer exists. Your page should now have:
    1. The first repeat region showing all the site's members first names.

    2. Just below the first repeat region, the First Name in your database as it would appear alphabetically.

  6. Go ahead and repeat steps four through six of the previous set of instructions to complete the second repeat region. There is no reason to apply the "rsMultiRepeat.MoveFirst()" code if you don't plan on using the recordset on the page again.

 

A slight detour of interest

Here is another example of using the MoveFirst() statement based on the above example.

  1. Go back and change the second repeat region to display only Five records. Save the page and preview it in your browser or with the UltraDev Live Data View. You will still see two repeat regions:
    1. The first region displays all the Member Names.

    2. The second region displays only the first five Member Names in the database.

  2. After the second repeat region, add a third rsMultiRepeat.M_FirstName to the page. Do not apply a repeat region to this one.

  3. Save the page and preview it in your browser or with the UltraDev Live Data View. You will again see two repeat regions followed by one instance of the M_FirstName you just applied.
    1. The first region displays all the Member Names.

    2. The second region displays only the first five Member Names in the database.

    3. Notice that the single instance of the M_FirstName you just applied is displaying the sixth record in your database? Compare the values of the first repeat region and the second repeat region - the first five will be exactly the same. And the single instance of the M_FirstName begins where the second repeat region left off.

      If you want, change the second repeat region to display values other than "5" records and you'll see that the single instance of the M_FirstName will always begin where the second repeat region finished. This is because the server has already looped through the first "x" amount of rows in your database based on the value you specified in the second repeat region and does not know you want to start at the beginning again.

      Also, you did not receive the error message because the server still had data left to display; you were not at the end of your records.

  4. If you want the single instance of the M_FirstName to display the first record in the database, add the rsMultiRepeat.MoveFirst() statement just after the "Wend" line in the second repeat region.

    <p><%=(rsMultiRepeat.Fields.Item("M_FirstName").Value)%></p>
    <%
    Repeat2__index=Repeat2__index+1
    Repeat2__numRows=Repeat2__numRows-1
    rsMultiRepeat.MoveNext()
    Wend
    rsMultiRepeat.MoveFirst()
    %>

Hopefully this interlude has helped provide a little insight into how the server is processing the information and displaying it on your page.

::This page last modified 8/13/2013 at 03:37::

Copyright © 2001-2019 DreamweaverFAQ.com All Rights Reserved.
All brands, trademarks, tutorials, extensions, code, and articles are the property of their respective owners.
A production of Site Drive Inc.
Legal Notice | Privacy Policy | Disclaimer & Notice