| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||||||||||||||||
|
|||||||||||||||||
|
ASP + CSS + DHTML Recursive Menu System
Here is an example of a Pure ASP Recursive Menu system.
CSS and DHTML can be added to format and style the menu. Menu output as HTML List http://computer-helpforum.com/asp/a...ee_Tutorial.asp Menu with DHTML Tree script/CSS applied http://computer-helpforum.com/asp/a...m_DHTMLTree.asp Files for the Recursive Menu, DHTML Tree script and Database can be found attached here http://forums.aspfree.com/showpost....205&postcount=4 Database Setup The first thing to do is structure the database. This example uses four tables Category - CatID (PK, Autonumber) - CatName (Text) SubCat - CatID (PK, Number) - SubCatID (PK, Number) Link - LinkID (PK, AutoNumber) - LinkName (Text) - LinkURL (Text) - LinkDescription (Memo) LinkCat - LinkID (PK, Number) - CatID (PK, Number) Categories are entered in the Categories table (Autonumber starting at 1). To determine Sub Categories, Category IDs are entered into the SubCat table along with it's Parent CatID e.g. Code:
CatID SubCat 1 0 2 1 3 1 This means that CatID 1 is the Sub Category of CatID 0. Seeing as though there cannot be a CatID of 0 then this makes CatID a top level menu. It cannot be a Sub Category. CatID 2 is a Sub Category of CatID 1 etc. The same method is applied the LinkCat table Database Joins The association in the script is made by using JOINs in the queries. e.g. For the listCat Sub proceduce query sql Code:
This query grabs the data from the Category table where the SubCatID in the SubCat table is equal to CatID e.g. CatID = 0 'get all top level categories The same method applies to the SubCat and the Link queries. HTML Output Once the query has been made the output can start. In this example the menu is output as a HTML List asp Code:
The Space() function, Counter variable and vbCRLF constant are used to provide source code formatting for the HTML output. Recursive Menu The way the recursive menu works is using while loops to check if a CatID has a SubCat associated with it. If it does then it calls the menu Sub procedure again, passing the new CatID. It will do this as many times as it finds a matching record in the query for the CatID. It will also call the listLink Sub procedure to ouput any links that are associated with the current SubCatID. Here is the code for the Sub procedures asp Code:
asp Code:
asp Code:
To start the menu system the listCat Sub procedure needs to be called, passing the top level CatID, which is 0 (Zero) Put this in the page where you want the menu to be output
__________________
CyberTechHelp Last edited by degsy : January 22nd, 2007 at 10:10 AM. |
|
#2
|
|||
|
|||
|
Note: This script has been stripped down. The Response.Write lines for the CSS/DHTML menu have been commented out. asp Code:
|