Cascade Record & Image Deletes
Creating the RecordsetsWe need to create three recordsets on the delete page. One recordset—rs_versions—will be conditional to keep the page from crashing when deleting categories without products. We will also need to custom code the SQL query to use the rs_products("P_ID") value to select the records from the versions table marked for deletion. The first recordset we’ll create is rs_categories. The only parameter we need to pass from our recordset navigation page to the delete record page is the Category_ID value. This will be the filter. If your navigation page uses links to select records for deletion, then the filter will be a URL querystring. If you use a drop down menu it will be a form variable. The rs_products recordset will use the same filter. For reference see the UD generated recordsets below: <% Nothing fancy there, but it gets interesting now. Create the recordset
rs_versions in the data bindings window. Don’t bother to set any filter
we will do that in code view. After you’ve created rs_versions, open the
Code Inspector. Notice the comment I’ve added to the code block and the
following conditional statement. If rs_products is empty rs_versions is
not created for two reasons. First the page will crash if it tries to
create rs_versions without a rs_products(“P_ID”) value. And second there
are no version images to delete because there are no versions. The next
code change is in the SQL query statement. We add a “Where” directive
and set the “Where” condition equal to the rs_products record ID number
(“P_ID”). When you’re done, close the “if then” statement, save the file,
and return to design view. When you get back to design view the first thing you should notice is that the rs_versions recordset has vanished from the data bindings window. Don’t panic—it’s supposed to do this. Go ahead and add the delete records server behavior to the page for rs_categories. Okay, now that we have the recordsets we need to get all the image names
for deletion. To accomplish this we need a repeat region to loop through
the Products table and one to loop through the Versions table and collect
image values for the delete. You can use any method to create two repeat
regions that works for you. I pull a field value from the Products table
and apply the repeat region behavior selecting show all records. I then
return to code view, copy and paste a copy of the repeat region and change
the variable names as shown. You could also drag field elements from the
Products and Versions onto the page before modifying rs_versions and cut
and paste the resulting code. Regardless of method you need two repeat
regions on the page one for rs_products and one for rs_versions. |
|||
|
James Threadgill
James Threadgill has authored numerous tutorials on ASP and ASP.NET web development, published on such sites as the Dynamic Zones and MSDN Accademic Alliance. He co-authored the Sam's book Dreamweaver MX: ASP.NET Web Development.
James first began computer programming in 1995 while attending Alvin Community College. He completed a certificate of computer science program and an Associate of Arts degree at Alvin before going on to the University of Houston-Clear Lake where he was awarded a Bachelor of Science and a Master of Arts.
James publishes fiction, poetry, and visual arts under the name Wayne James. His fiction first appeared in Raconteur in 1995 and since has been published numerous times: in Hadrosaur Tales 5 and 7, Bayousphere, and in the Write Gallery e-zine. His poetry first appeared in the small press magazine Lucidity in 1996 and has been published numerous times since. His collection of fiction and poetry, When Only the Moon Rages, was released in 2000. Most recently his work appeared in Tales of the Talisman winter 2010 and spring 2011 issues. James currently attends graduate school at the University of Houston and owns and operates small web design and internet marketing firm, WWWeb Concepts, with his wife, Karen, in Houston, TX USA.
Comments
DMX 2004 and the Cascade delete
Firstly thank you for your tutorials, I am very grateful. I am going to give the Cascade Record and Images deletes a go and was wondering, using mx2004 has things changed any to make it a little easier to do this.
Regards
Kenny
RE: DMX 2004 and the Cascade delete
You are welcome, Kenny. I was quite ill when you posted, but I'm back now!
Cascading file deletes are pretty complex considering the loops required. I wouldn't expect DMX to make this sort of thing point and click anytime soon.
RE: RE: DMX 2004 and the Cascade delete
re " I wouldn't expect DMX to make this sort of thing point and click anytime soon."
I have found the MX Kollection from Interakt does just that.
regards
Kenny
You must me logged in to write a comment.