【asp源码栏目提醒】:网学会员在asp源码频道为大家收集整理了“asp net 实现购物车详细代码 - 计算机教材“提供大家参考,希望对大家有所帮助!
以上为HTML页面部分 using System using System.Collections using System.ComponentModel using System.Web.SessionState using System.Web using System.Web.UI using System.Web.UI.HtmlControls using System.Web.UI.WebControls using System.Data using System.Data.OleDb using System.Configuration namespace myshop /// /// shoppingcart 的摘要说明. /// public class shoppingcart : System.Web.UI.Page protected System.Web.UI.WebControls.DataGrid ShoppingCartDlt protected System.Web.UI.WebControls.Button update protected System.Web.UI.WebControls.Button CheckOut protected System.Web.UI.HtmlControls.HtmlForm Form1 protected System.Web.UI.WebControls.Label label protected System.Web.UI.WebControls.CheckBox chkProductID protected System.Web.UI.WebControls.TextBox txtCount protected System.Web.UI.WebControls.TextBox CountTb string AddProID private void Page_Load object sender System.EventArgs e try if SessionlogonyesSessionusernamenull Response.Redirect error.htm catch Response.Redirect error.htm /////////////查看用户是否已经登陆. if IsPostBack if Request.Paramsmodeview //检测是否为直接查看购物车. ViewShoppingCart Caculator if Request.ParamsproductIDnullRequest.ParamsproductID AddProIDRequestproductID UpdateShoppingCart Caculator // 在此处放置用户代码以初始化页面 public void CreateCartTable //创建购物车 DataSet ds new DataSet DataTable newDTnew DataTable CartTable ds.Tables.Add newDT DataColumn newDC newDCnew DataColumn ProdIDSystem.Type.GetType System.Int32 ds.TablesCartTable.Columns.Add newDC newDCnew DataColumn ProdCountSystem.Type.GetType System.Int32 newDC.DefaultValue1 ds.TablesCartTable.Columns.Add newDC newDCnew DataColumn ProNameSystem.Type.GetType System.String ds.TablesCartTable.Columns.Add newDC newDCnew DataColumn UnitPriceSystem.Type.GetType System.Double ds.TablesCartTable.Columns.Add newDC newDCnew DataColumn TotalPriceSystem.Type.GetType System.Double ds.TablesCartTable.Columns.Add newDC newDCnew DataColumn IsDeletedSystem.Type.GetType System.Int32 newDC.DefaultValue0 // public void WriteShoppingCart 中 newDR50 行已被注销 ds.TablesCartTable.Columns.Add newDC SessionmyCartTablenewDT ShoppingCartDlt.DataSourceds.TablesCartTable.DefaultView ShoppingCartDlt.DataBind public void UpdateShoppingCart if SessionmyCartTablenull //SessionmyCartTablenull CreateCartTable //调用函数CreateCartTable 新建一个DataTable WriteShoppingCart else //如果购物蓝中已有商品则需要对购物信息表DataTable进行更新并将其棒定到ShoppingCartDlt WriteShoppingCart public void ViewShoppingCart //查看购物车 if SessionmyCartTablenull DataTable viewTablenew DataTable nowCartTable viewTable DataTable SessionmyCartTable ShoppingCartDlt.DataSource viewTable.DefaultView //购物车棒定到ShoppingCartDlt ShoppingCartDlt.DataBind public void WriteShoppingCart if Request.Paramsmodeview //检查是否是直接查看购物车如果直接查看就不再写MYCARTTABLE DataTable nowTablenew DataTable nowCartTable nowTable DataTable SessionmyCartTable int pnnowTable.Rows.Count int i0 bool hasonefalse int nowProdID while i0 //返回购物车中是否有货物 for h0 h