Description: The Menu user control displays a list of all product categories and subcategories within the Adventure Works Cycles database, and enables a user to easily navigate off to a product subcategory listing page that lists all of the actual products within that subcategory.
Implementation Notes: The Menu user control is used on almost every page within the Adventure Works Cycles application.
It's logic is encapsulated entirely within its Page_Load and OnPreRender event handlers. The Page_Load event handler is called when a page containing the Menu user control is accessed by a browser client.
Page_Load Event Handler: The Page_Load event handler creates an instance of the ProductDB class and calls its GetProductTree method. This method internally uses the usp_ProductCategoryList stored procedure to fetch the product categories and subcategories from the Adventure Works Cycles database.
The product category and subcategory collections are displayed using a tree server control. The tree server control contains an embedded XML document which indicates how categories and subcategories should rendered. In particular, the document specifies that selected subcategories be rendered differently from unselected nodes in the tree control.
The data values returned from the ProductsDB.GetProductTree() method are populated into the tree control by setting its TreeNodeSrc property, and then calling its DataBind() method. When DataBind() is called, the tree control will walk over the XML and render the categories and subcategories as a two level tree.
Performance Notes: