I completely agree with Jimmy, it will make maintenance very easy as well as promote a good OO design methodology. I put together an extremely simple example in C#. For the price I only set 2 values and again this is a very very simple example.
Default.aspx
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="My Product Page"></asp:Label>
<br /><br />
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True">
<asp:ListItem>Shirts</asp:ListItem>
<asp:ListItem>Sweaters</asp:ListItem>
<asp:ListItem>Coats</asp:ListItem>
<asp:ListItem>Pants</asp:ListItem>
</asp:ListBox>
<br />
<br />
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem>Small</asp:ListItem>
<asp:ListItem>Medium</asp:ListItem>
<asp:ListItem>Large</asp:ListItem>
<asp:ListItem>X-Large</asp:ListItem>
<asp:ListItem>XX-Large</asp:ListItem>
</asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True">
<asp:ListItem>Black</asp:ListItem>
<asp:ListItem>White</asp:ListItem>
<asp:ListItem>Green</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
<asp:ListItem>Yellow</asp:ListItem>
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>Orange</asp:ListItem>
<asp:ListItem>Brown</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server" Width="46px"></asp:TextBox><br />
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Order" /><br />
<br />
<br />
</div>
</form>
Default.aspx.cs
protected void Button1_Click(object sender, EventArgs e)
{
ShoppingCart cart = new ShoppingCart();
cart.ProductID = 1;
cart.ProductName = ListBox1.SelectedItem.Value;
cart.ProductDescription = "Some Description";
cart.Quantity = Convert.ToInt32(TextBox1.Text);
cart.Size = DropDownList1.SelectedItem.Value;
cart.Color = DropDownList2.SelectedItem.Value;
if (cart.ProductName == "Sweaters" && cart.Size == "XX-Large")
cart.Price = 29.95M;
else
cart.Price = 19.95M;
Session["Order"] = cart;
Response.Redirect("~/OrderDetails.aspx");
}ShoppingCart.cs
public class ShoppingCart
{
private string size;
public string Size
{
get { return size; }
set { size = value; }
}
private string color;
public string Color
{
get { return color; }
set { color = value; }
}
private int productID;
public int ProductID
{
get { return productID; }
set { productID = value; }
}
private string productName;
public string ProductName
{
get { return productName; }
set { productName = value; }
}
private string productDescription;
public string ProductDescription
{
get { return productDescription; }
set { productDescription = value; }
}
private int quantity;
public int Quantity
{
get { return quantity; }
set { quantity = value; }
}
private decimal price;
public decimal Price
{
get { return price; }
set { price = value; }
}
}
OrderDetails.aspx
form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Your Order"></asp:Label>
<br />
<br />
<asp:Label ID="Label" runat="server" Text="ProductID:"></asp:Label>
<asp:Label ID="ProductIDLabel" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Text="Product Name:"></asp:Label>
<asp:Label ID="ProductNameLabel" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label3" runat="server" Text="Description:"></asp:Label>
<asp:Label ID="ProductDescriptionLabel" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label4" runat="server" Text="Quantity:"></asp:Label>
<asp:Label ID="ProductQtyLabel" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label5" runat="server" Text="Size:"></asp:Label>
<asp:Label ID="ProductSizeLabel" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label6" runat="server" Text="Color:"></asp:Label>
<asp:Label ID="ProductColorLabel" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label7" runat="server" Text="Price:"></asp:Label>
<asp:Label ID="ProductPriceLabel" runat="server" Text="Label"></asp:Label></div>
</form>
OrderDetails.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
ShoppingCart order = new ShoppingCart();
order = Session["Order"] as ShoppingCart;
ProductIDLabel.Text = order.ProductID.ToString();
ProductNameLabel.Text = order.ProductName;
ProductDescriptionLabel.Text = order.ProductDescription;
ProductQtyLabel.Text = order.Quantity.ToString();
ProductSizeLabel.Text = order.Size;
ProductColorLabel.Text = order.Color;
ProductPriceLabel.Text = order.Price.ToString();
}