主题:[讨论]为什么我的购物商品获取不到购物车
<%@ Page language="c#" Codebehind="Cart.aspx.cs" AutoEventWireup="false" Inherits="BBSCart.Cart" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Cart</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<FONT face="宋体">
<FORM id="Form1" method="post" runat="server">
<asp:LinkButton id="btnShop" Text="继续购物" Runat="server"></asp:LinkButton>
<asp:DataGrid id="dg" Runat="server" AutoGenerateColumns="False" BorderColor="White" BorderStyle="Ridge"
CellSpacing="1" BorderWidth="2px" BackColor="White" CellPadding="3" GridLines="None">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#9471DE"></SelectedItemStyle>
<ItemStyle ForeColor="Black" BackColor="#DEDFDE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#E7E7FF" BackColor="#4A3C8C"></HeaderStyle>
<FooterStyle ForeColor="Black" BackColor="#C6C3C6"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="id" HeaderText="物品ID"></asp:BoundColumn>
<asp:BoundColumn DataField="Name" HeaderText="名称"></asp:BoundColumn>
<asp:BoundColumn DataField="Price" HeaderText="价格" DataFormatString="{0:c}"></asp:BoundColumn>
<asp:BoundColumn DataField="Count" HeaderText="数量"></asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Right" ForeColor="Black" BackColor="#C6C3C6"></PagerStyle>
</asp:DataGrid>
<asp:Label id="lblTotalPrice" Runat="server" Font-Size="20"></asp:Label></FORM>
</FONT>
</body>
</HTML>
Cart.aspx的代码
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace BBSCart
{
/// <summary>
/// Cart 的摘要说明。
/// </summary>
public class Cart : System.Web.UI.Page
{
protected System.Web.UI.WebControls.LinkButton btnShop;
protected System.Web.UI.WebControls.DataGrid dg;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.Label lblTotalPrice;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
ShopCart sc=Session["sc"] as ShopCart;
if(sc!=null)
{
if(!IsPostBack)
{
dg.DataSource=sc.GetShopWpList();
dg.DataBind();
this.lblTotalPrice.Text=string.Format("总价格是:{0:c}", sc.TotalPrice);
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnShop.Click += new System.EventHandler(this.btnShop_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnShop_Click(object sender, System.EventArgs e)
{
Response.Redirect("index.aspx");
}
}
}
Cart.aspx.cs的代码
<%@ Page language="c#" Codebehind="index.aspx.cs" AutoEventWireup="false" Inherits="BBSCart.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>index</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<table width="776" border="0" align="center" cellpadding="0" cellspacing="0" background="image/topbg.gif">
<!--DWLayoutTable-->
<tr>
<td height="11" colspan="3" valign="top"><img src="image/top.gif" width="776" height="11"></td>
</tr>
<tr>
<td width="190" height="68" align="center" valign="middle"><img src="image/title.gif" width="180" height="60"></td>
<td width="489" align="center" valign="middle"><img src="image/banner.gif" width="468" height="62"></td>
<td width="97" align="center" valign="middle" class="font">◎ <A href="javascript:window.external.addFavorite('http://www.cncss.com','模板精品店')">
加入收藏</A><br>
<a href="#" onClick="this.style.behavior='url(#default#homepage)';this.sethomepage('http://www.cncss.com');return false;">
◎ 设为首页</a><br>
<a href="about.htm">◎ 关于我们</a></td>
</tr>
<tr class="font">
<td height="25" colspan="3" align="right" valign="middle" background="image/bj.gif">
回到首页 | 公司简介 | 公司架构 | 服务中心 | 动态新闻 | 公司论坛 | 签写留言 | 人才招聘 | 联系方法 |</td>
</tr>
</table>
<table width="776" border="0" align="center" cellpadding="0" cellspacing="0" background="image/topbg.gif">
<!--DWLayoutTable-->
<tr>
<td height="11" colspan="2" valign="top"><!--DWLayoutEmptyCell--> </td>
</tr>
<tr>
<td width="237" rowspan="2" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="237" height="216" valign="top" align="center"><IFRAME frameBorder="0" height="100%" marginHeight="0" marginWidth="0" scrolling="yes" src="news.htm"
width="100%"> </IFRAME>
</td>
</tr>
</table>
</td>
<td width="539" height="191" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="539" height="191">声明:此模板为penzi原创作品<br>
原创站点为:中国设计站(www.htmcn.com)网友<a href="mailto:13131@163.com" target="_blank">于文书</a>提供<br>
<br>
更多、更好的模板,请来模板精品店<br>
http://www.cncss.com</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="25" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="494" height="25" valign="top" background="image/right2.gif"><!--DWLayoutEmptyCell-->
</td>
<td width="45" valign="top"><img src="image/right.gif" width="45" height="25"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="11" colspan="2" valign="top"><img src="image/top.gif" width="776" height="11"></td>
</tr>
<tr>
<td height="200" colspan="2" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<TBODY>
<tr>
<td align="center" valign="middle" bgcolor="#ffffff"><FONT face="宋体"></FONT>
</td>
</tr>
</TBODY>
</table>
<form id="form1" method="post" runat="server">
<asp:LinkButton ID="btnViewCart" Text="查看购物车" Runat="server" />
<br>
<asp:DataGrid ID="dg" Runat="server" AutoGenerateColumns="False" BorderColor="#999999" BorderStyle="None"
BorderWidth="1px" BackColor="White" CellPadding="3" GridLines="Vertical" Width="778px">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
<ItemStyle ForeColor="Black" BackColor="#EEEEEE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#000084"></HeaderStyle>
<FooterStyle ForeColor="Black" BackColor="#CCCCCC"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="wpID" HeaderText="物品ID"></asp:BoundColumn>
<asp:BoundColumn DataField="wpName" HeaderText="名称"></asp:BoundColumn>
<asp:BoundColumn DataField="wpPrice" HeaderText="价格" DataFormatString="{0:c}"></asp:BoundColumn>
<asp:ButtonColumn Text="添加到购物车" CommandName="AddToCart"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="Black" BackColor="#999999" Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
</form>
</td>
</tr>
<tr>
<td height="11" colspan="2" valign="top"><img src="image/top.gif" width="776" height="11"></td>
</tr>
<tr>
</tr>
<tr class="td">
<td height="11" colspan="2" valign="top"><img src="image/bottom.gif" width="776" height="11"></td>
</tr>
<tr>
<td height="91" colspan="2" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="26" height="91" valign="top"><img src="image/left2.gif" width="26" height="91"></td>
<td width="218" valign="top"><!--DWLayoutEmptyCell-->
</td>
<td width="347" valign="middle" class="font">地址:广州天河石牌西路1-7号太平洋二期G607<br>
电话:020-87580720 87563432<br>
传真:020-87585475<br>
维修中心:020-87585475-114
<br>
E-mail: gzct@pcct.com.cn
</td>
<td width="185" align="center" valign="middle"><img src="image/lgle90.gif" width="90" height="50"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="16" colspan="2" valign="top" bgcolor="#333333"><FONT face="宋体"></FONT></td>
</tr>
</table>
</body>
</HTML>
Index.aspx的代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Cart</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<FONT face="宋体">
<FORM id="Form1" method="post" runat="server">
<asp:LinkButton id="btnShop" Text="继续购物" Runat="server"></asp:LinkButton>
<asp:DataGrid id="dg" Runat="server" AutoGenerateColumns="False" BorderColor="White" BorderStyle="Ridge"
CellSpacing="1" BorderWidth="2px" BackColor="White" CellPadding="3" GridLines="None">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#9471DE"></SelectedItemStyle>
<ItemStyle ForeColor="Black" BackColor="#DEDFDE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#E7E7FF" BackColor="#4A3C8C"></HeaderStyle>
<FooterStyle ForeColor="Black" BackColor="#C6C3C6"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="id" HeaderText="物品ID"></asp:BoundColumn>
<asp:BoundColumn DataField="Name" HeaderText="名称"></asp:BoundColumn>
<asp:BoundColumn DataField="Price" HeaderText="价格" DataFormatString="{0:c}"></asp:BoundColumn>
<asp:BoundColumn DataField="Count" HeaderText="数量"></asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Right" ForeColor="Black" BackColor="#C6C3C6"></PagerStyle>
</asp:DataGrid>
<asp:Label id="lblTotalPrice" Runat="server" Font-Size="20"></asp:Label></FORM>
</FONT>
</body>
</HTML>
Cart.aspx的代码
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace BBSCart
{
/// <summary>
/// Cart 的摘要说明。
/// </summary>
public class Cart : System.Web.UI.Page
{
protected System.Web.UI.WebControls.LinkButton btnShop;
protected System.Web.UI.WebControls.DataGrid dg;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.Label lblTotalPrice;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
ShopCart sc=Session["sc"] as ShopCart;
if(sc!=null)
{
if(!IsPostBack)
{
dg.DataSource=sc.GetShopWpList();
dg.DataBind();
this.lblTotalPrice.Text=string.Format("总价格是:{0:c}", sc.TotalPrice);
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnShop.Click += new System.EventHandler(this.btnShop_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnShop_Click(object sender, System.EventArgs e)
{
Response.Redirect("index.aspx");
}
}
}
Cart.aspx.cs的代码
<%@ Page language="c#" Codebehind="index.aspx.cs" AutoEventWireup="false" Inherits="BBSCart.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>index</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<table width="776" border="0" align="center" cellpadding="0" cellspacing="0" background="image/topbg.gif">
<!--DWLayoutTable-->
<tr>
<td height="11" colspan="3" valign="top"><img src="image/top.gif" width="776" height="11"></td>
</tr>
<tr>
<td width="190" height="68" align="center" valign="middle"><img src="image/title.gif" width="180" height="60"></td>
<td width="489" align="center" valign="middle"><img src="image/banner.gif" width="468" height="62"></td>
<td width="97" align="center" valign="middle" class="font">◎ <A href="javascript:window.external.addFavorite('http://www.cncss.com','模板精品店')">
加入收藏</A><br>
<a href="#" onClick="this.style.behavior='url(#default#homepage)';this.sethomepage('http://www.cncss.com');return false;">
◎ 设为首页</a><br>
<a href="about.htm">◎ 关于我们</a></td>
</tr>
<tr class="font">
<td height="25" colspan="3" align="right" valign="middle" background="image/bj.gif">
回到首页 | 公司简介 | 公司架构 | 服务中心 | 动态新闻 | 公司论坛 | 签写留言 | 人才招聘 | 联系方法 |</td>
</tr>
</table>
<table width="776" border="0" align="center" cellpadding="0" cellspacing="0" background="image/topbg.gif">
<!--DWLayoutTable-->
<tr>
<td height="11" colspan="2" valign="top"><!--DWLayoutEmptyCell--> </td>
</tr>
<tr>
<td width="237" rowspan="2" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="237" height="216" valign="top" align="center"><IFRAME frameBorder="0" height="100%" marginHeight="0" marginWidth="0" scrolling="yes" src="news.htm"
width="100%"> </IFRAME>
</td>
</tr>
</table>
</td>
<td width="539" height="191" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="539" height="191">声明:此模板为penzi原创作品<br>
原创站点为:中国设计站(www.htmcn.com)网友<a href="mailto:13131@163.com" target="_blank">于文书</a>提供<br>
<br>
更多、更好的模板,请来模板精品店<br>
http://www.cncss.com</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="25" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="494" height="25" valign="top" background="image/right2.gif"><!--DWLayoutEmptyCell-->
</td>
<td width="45" valign="top"><img src="image/right.gif" width="45" height="25"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="11" colspan="2" valign="top"><img src="image/top.gif" width="776" height="11"></td>
</tr>
<tr>
<td height="200" colspan="2" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<TBODY>
<tr>
<td align="center" valign="middle" bgcolor="#ffffff"><FONT face="宋体"></FONT>
</td>
</tr>
</TBODY>
</table>
<form id="form1" method="post" runat="server">
<asp:LinkButton ID="btnViewCart" Text="查看购物车" Runat="server" />
<br>
<asp:DataGrid ID="dg" Runat="server" AutoGenerateColumns="False" BorderColor="#999999" BorderStyle="None"
BorderWidth="1px" BackColor="White" CellPadding="3" GridLines="Vertical" Width="778px">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
<ItemStyle ForeColor="Black" BackColor="#EEEEEE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#000084"></HeaderStyle>
<FooterStyle ForeColor="Black" BackColor="#CCCCCC"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="wpID" HeaderText="物品ID"></asp:BoundColumn>
<asp:BoundColumn DataField="wpName" HeaderText="名称"></asp:BoundColumn>
<asp:BoundColumn DataField="wpPrice" HeaderText="价格" DataFormatString="{0:c}"></asp:BoundColumn>
<asp:ButtonColumn Text="添加到购物车" CommandName="AddToCart"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="Black" BackColor="#999999" Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
</form>
</td>
</tr>
<tr>
<td height="11" colspan="2" valign="top"><img src="image/top.gif" width="776" height="11"></td>
</tr>
<tr>
</tr>
<tr class="td">
<td height="11" colspan="2" valign="top"><img src="image/bottom.gif" width="776" height="11"></td>
</tr>
<tr>
<td height="91" colspan="2" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="26" height="91" valign="top"><img src="image/left2.gif" width="26" height="91"></td>
<td width="218" valign="top"><!--DWLayoutEmptyCell-->
</td>
<td width="347" valign="middle" class="font">地址:广州天河石牌西路1-7号太平洋二期G607<br>
电话:020-87580720 87563432<br>
传真:020-87585475<br>
维修中心:020-87585475-114
<br>
E-mail: gzct@pcct.com.cn
</td>
<td width="185" align="center" valign="middle"><img src="image/lgle90.gif" width="90" height="50"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="16" colspan="2" valign="top" bgcolor="#333333"><FONT face="宋体"></FONT></td>
</tr>
</table>
</body>
</HTML>
Index.aspx的代码