Description: The Menu user control displays a list of all product categories within the IBuySpy database, and enables a user to easily navigate off to a product category listing page that lists all of the actual products within that category.
Implementation Notes: The Menu user control is used on almost every page within the IBuySpy application.
It's logic is encapsulated entirely within its Page_Load event handler. This 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 GetProductCategories method. This method internally uses the ProductCategoryList stored procedure to fetch the product categories from the IBuySpy database.
The product category collection is displayed using a templated <asp:DataList> server control. The DataList server control contains two user-defined templates that describe how the list should look. ItemTemplate defines what each item in the list should look like; and SelectedItemTemplate defines a different appearance for the the currently selected item. In this case, the SelectedItemTemplate applies a different CSS Class to the hyperlink within it.
The data values returned from the ProductsDB.GetProductCategories() method are populated into the DataList by setting its Datasource property, and then calling its DataBind() method. When DataBind() is called, the DataList will iterate over the DataSource and render a copy of the ItemTemplate -- or SelectedItemTemplate -- for each row, populating it data from the row.
Peformance Notes: