温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:JaneLee简单购物车源码
当前文件:
JaneLeeShopCart/mycart.aspx.cs[2K,2009-6-12 11:45:29],打开代码结构图
JaneLeeShopCart/mycart.aspx.cs[2K,2009-6-12 11:45:29],打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
//该源码下载自www.51aspx.com(51aspx.com) 12
13
public partial class mycart : System.Web.UI.Page 14
{ 15
protected void Page_Load(object sender, EventArgs e) 16
{ 17
if (!IsPostBack) 18
{ 19
GridView1.DataSource = Session["shoppingcart"]; 20
GridView1.DataBind(); 21
} 22
} 23
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 24
{ 25
DataTable Cart = new DataTable(); 26
if (e.CommandName == "buy") 27
{ 28
if (Session["ShoppingCart2"] == null) 29
{ 30
Cart.Columns.Add("商品编号", typeof(int)); //建立数据表结构 31
Cart.Columns.Add("商品名称", typeof(string)); 32
Cart.Columns.Add("单位数量", typeof(string)); 33
Cart.Columns.Add("单价", typeof(double)); 34
Cart.Columns.Add("订购数量", typeof(int)); 35
//Cart.Columns.Add("折扣", typeof(double)); 36
Cart.Columns.Add("合计", typeof(double)); 37
Session["ShoppingCart2"] = Cart; 38
} 39
Cart = (DataTable)Session["ShoppingCart2"]; 40
if (TextBox1.Text == "") // 输入客户标志 41
{ 42
Validate(); // 调用校验控件进行校验 43
} 44
else 45
{ 46
Session["khbz"] = TextBox1.Text; 47
int index = Convert.ToInt32(e.CommandArgument); 48
GridViewRow row = GridView1.Rows[index]; 49
TextBox tt = (TextBox)row.Cells[1].FindControl("TextBox2"); 50
string dgl = tt.Text; 51
int dg = int.Parse(dgl); 52
if (dg <= 1) 53
dg = 1; 54
string bhText = row.Cells[2].Text; 55
string mcText = row.Cells[3].Text; 56
string dwText = row.Cells[4].Text; 57
string djText = row.Cells[5].Text; 58
int bh = int.Parse(bhText); 59
double dj = double.Parse(djText); 60
DataRow rr = Cart.NewRow(); 61
rr["商品编号"]=bh; 62
rr["商品名称"] = mcText; 63
rr["单位数量"] = dwText; 64
rr["单价"] = dj; 65
rr["订购数量"] = dg; 66
//int zk = 1; 67
//rr["折扣"] = zk; 68
double hj = dj * dg; 69
rr["合计"] = hj; 70
Cart.Rows.Add(rr); 71
Session["ShoppingCart2"] = Cart; 72
} 73
} 74
} 75
} 76
77
78
79






}
}