PopularItems User Control

Description: The PopularItems user control displays a list of the top 5 most popular items purchased from Adventure Works Cycles, and enables users to easily navigate off to read details about each one.

Click here to learn more about what user controls are and how they are used within ASP.NET Web Applications

Implementation Notes:   This control is used on the Adventure Works Cycles application home page.

The PopularItems user control logic is encapsulated entirely within its Page_Load  event handler.  This event handler is called when a page containing the 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 GetMostPopularProductsOfWeek method, passing it the product ID. This method internally uses the usp_ProductsMostPopular stored procedure to fetch the product information from the Adventure Works Cycles database. 

The product collection is displayed using a templated <asp:Repeater> server control.  As used in this user control, the Repeater server control contains three user-defined templates -- HeaderTemplate, ItemTemplate and FooterTemplate -- that describe how the list should look.  The ItemTemplate defines how the bound data is displayed; the HeaderTemplate defines HTML that is emitted at the beginning of the list; and the FooterTemplate defines HTML that is emitted at the end of the list.

The data values returned from the ProductsDB.GetMostPopularProductsOfWeek() method are populated into the Repeater by setting its Datasource property, and then calling its DataBind()  method.  When DataBind() is called, the Repeater will render its HeaderTemplate, then iterate over the DataSource and render a copy of the ItemTemplate for each row, populating it data from the row.  Finally, the Repeater will render its FooterTemplate. 

Performance Notes: