LISTING 1: THE SQLDATASOURCE CONTROL AND ITS NESTED CONTROLPARAMETER

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ... >
<InsertParameters>
...
</InsertParameters>
<UpdateParameters>
...
</UpdateParameters>
<DeleteParameters>
...
</DeleteParameters>
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1"
Name="ProductSubcategoryID" PropertyName="SelectedValue"
Type="Int16" />
</SelectParameters>
</asp:SqlDataSource>

LISTING 2: THE DATA ACCESS COMPONENT IMPLEMENTED AS A CLASS FILE

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public class DataLayer
{
public DataSet GetProductsByCategory(Int32 category)
{
String connect = ConfigurationManager.ConnectionStrings[
"AdventureWorksConnectionString1"].ConnectionString;
String sql = "SELECT ProductID, Name, ProductNumber, Color, "
+ "StandardCost, ListPrice, ProductSubcategoryID "
+ "FROM AdventureWorks.Production.Product "
+ "WHERE ProductSubcategoryID = @Category";
using (SqlConnection con = new SqlConnection(connect))
{
SqlDataAdapter da = new SqlDataAdapter(sql, con);
da.SelectCommand.Parameters.AddWithValue("@Category", category);
DataSet ds = new DataSet();
da.Fill(ds, "Products");
return ds;
}
}
public DataSet GetProductByProductID(Int32 pid)
{
String connect = ConfigurationManager.ConnectionStrings[
"AdventureWorksConnectionString1"].ConnectionString;
String sql = "SELECT ProductID, Name, ProductNumber, "
+ "SafetyStockLevel, Color, FinishedGoodsFlag, "
+ "MakeFlag, ReorderPoint, StandardCost, ListPrice, "
+ "Size, DaysToManufacture, Weight, "
+ "WeightUnitMeasureCode, SizeUnitMeasureCode, "
+ "ProductSubcategoryID, Style, Class, ProductLine, "
+ "ProductModelID, SellStartDate, SellEndDate, "
+ "DiscontinuedDate "
+ "FROM AdventureWorks.Production.Product "
+ "WHERE ProductID = @ProductID";
using (SqlConnection con = new SqlConnection(connect))
{
SqlDataAdapter da = new SqlDataAdapter(sql, con);
da.SelectCommand.Parameters.AddWithValue("@ProductID", pid);
DataSet ds = new DataSet();
da.Fill(ds, "Products");
return ds;
}
}
public SqlDataReader GetCategoryList()
{
String connect = ConfigurationManager.ConnectionStrings[
"AdventureWorksConnectionString1"].ConnectionString;
String sql = "SELECT ProductSubcategoryID, Name "
+ "FROM AdventureWorks.Production.ProductSubcategory";
SqlConnection con = new SqlConnection(connect);
try
{
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
catch
{
return null;
}
}
}


LISTING 3: THE SOURCE CODE OF THE ADVENTUREWORKS MASTER PAGE

<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>AdventureWorks Inc.</title>
<link rel="Stylesheet" type="text/css"
href="StyleSheet.css" title="Default" />
</head>
<body topmargin="0" leftmargin="0" rightmargin="0">
<form id="form1" runat="server">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left" colspan="3" bgcolor="#000000">
<img src="Images/header.jpg" border="0" vspace="0" />
</td>
</tr>
<tr>
<td bgcolor="#000000"> </td>
<td style="padding:10px">
<asp:ContentPlaceholder id="CP1" runat="server" />
</td>
<td bgcolor="#000000"> </td>
</tr>
<tr>
<td align="center" colspan="3" bgcolor="#000000">
<span class="footer">
AdventureWorks Inc. is a fictional corporation.
</span>
</td>
</tr>
</table>
</form>
</body>
</html>


LISTING 4: THE OUTLINE STRUCTURE OF A CONTENT PAGE

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Products.aspx.cs" Inherits="Products"
MasterPageFile="~/MasterPage.master" %>
<asp:Content ContentPlaceHolderID="CP1" runat="server" ID="Content1">
... all page content goes here ...
</asp:Content>