日期:2014-05-17  浏览次数:20567 次

如何计算总价?
这是我的代码,订购相应产品的总价已经计算出来了,但是我想得出的是如果买一个产品是一个产品的总价,买两个产品显示的是两个产品的总价而不是第二个产品的总价,要怎么编写代码?
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        DataTable Cart = new DataTable();
        if (e.CommandName == "select")
        {
            if (Session["shop"] == null)//如果没有购物车数据的话
            {
                Cart.Columns.Add("编号", typeof(int));
                Cart.Columns.Add("名称", typeof(string));
                Cart.Columns.Add("规格", typeof(string));
                Cart.Columns.Add("单价", typeof(double));
                Cart.Columns.Add("数量", typeof(int));
                Cart.Columns.Add("总价", typeof(double));
                Session["shop"] = Cart;//把购物车的虚拟表结构存储入session
            }

            Cart = (DataTable)Session["shop"];//从session中取出之前的购物数据

            int index = Convert.ToInt32(e.CommandArgument);//获取选择行的id号
            GridViewRow row = GridView1.Rows[index];//获取行
            int id = Convert.ToInt32(row.Cells[0].Text);//商品ID
            string name = row.Cells[1].Text;//商品名称
            string size = row.Cells[2].Text;//商品规格
            string p = row.Cells[3].Text;//
            double price = double.Parse(p);//商品单价
            int count = Convert.ToInt32(((TextBox)row.FindControl("TextBox1")).Text);//商品数量

            //添加一行购物数据
            DataRow rr = Cart.NewRow();//定义一个新行
            rr["编号"] = id;
            rr["名称"] = name;
            rr["规格"] = size;
            rr["单价"] = price;
            rr["数量"] = count;
            rr["总价"] = price * count;
&nb