The FeaturedItems.ascx.cs Code Behind Class

We needed to add code to get the list of featured items out of the database and display it on the Web site. This functionality was easily added to the FeaturedItems.ascx.cs code behind class.

The easiest and most logical place to add the data access code was the Page_Load method. Listing 7.3 shows the implementation of this method.

Listing 7.3. The FeaturedItems.ascx.cs Code Behind Class' Page_Load Method
 private void Page_Load(object sender, System.EventArgs e) { SqlConnection conn = new SqlConnection(ConnectionString); SqlCommand myCommand = new SqlCommand("spGetFeaturedItems", conn); // set the command type as a SP myCommand.CommandType = CommandType.StoredProcedure; // Add Parameters SqlParameter ...

Get Building e-Commerce Sites with the .NET Framework now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.