Nested Repeat Region using a Recordset Filter
T-Cubed
Tom's Top Tutorials - Ultradev/ASP
nested repeat region using a filter
This
tutorial assumes that you are proficient at:
Editing code using HTML Source Window or Code View in UD4
First there are a few words of caution about using this method of nested repeats. The database results inside the repeat region are filtered down to the appropriate entries based on your defined relationship in the code. The recordset is filtered on every loop of the main repeat region. If there a many thousands of items in this second recordset, this could reduce performance of the page as the recordset has to have all entries available before filtering.
There are other methods such as Data Shaping which I will be covering soon.
1. Create a recordset. This will be the master recordset used for the repeat region. Use any filter as appropriate to reduce the number of results returned.
2. Create a second recordset. This recordset will be the one that is filtered inside the repeat region. This should include ALL records (IE SELECT * FROM mytable).
3. Create a 2 row table on the page.
4. Drag the column from the initial recordset that you want to show as the header.
5. Select the table and apply the repeat region server behaviour using the initial recordset.
6. Now you need to add the code shown below:
<% FilterParam = MasterRecordset.Fields.Item("MasterFilterColumn").Value SecondRecordset.Filter = "SecondRecordsetFilterColumn = " & FilterParam While (NOT SecondRecordset.EOF) %> <%=(SecondRecordset.Fields.Item("FieldToDisplay").Value)%>, <% SecondRecordset.MoveNext() Wend %> |
Replace the Items in Red with your Recordset Names. The items in Blue, are the relationship between the two tables. These are normally your ID values. Replace these with appropriate values from your database.
Add the code into place as shown below. This is an example only. This will place it on the second row of the table. As long as the code is inbetween the 'While' statement and the 'Wend' statement, you will be ok.
Once you are happy with the results you can format them as you wish.
In the design view you will see something like this:
If for example you wanted to move rsPages.Description to another cell, be sure to highlight not only the word but also the ASP sheild icons at either side. This ensures that all the appropriate code get copied as well.
Comments
A question
Thank you for the great tutorial. I have a problem: I'm just a beggineg so my question could be easy. I'd doing a websitefor my friend's company which stores some information about donors and projects they had done, so I've got two tables in my database, one is list of donors with primary key DonorID and the second - projects. My friend needs a rable in his site with information like this:
Donor Name - Project Done - total amount of money he spent on projects
How can I do this??
Thank you
error
sorry,
it was wrong to type 'project done' - it must be "number of done projects"
Thanks
Same table?
Hi
Is it possible to use the same table for both queries? as I wish to use the first returned recordset to display the title, then a repeated region below to show the other data, using the same column name for both, then reapeating....
Thanks
Tony
RE: Same table?
You must me logged in to write a comment.