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

错误1运算符“*”无法应用于“int”和“方法组”类型的操作数
protected void Page_Load(object sender, EventArgs e)
    {
        ArrayList shopCartList = (ArrayList)Session["shopList"];
        GridView1.DataSource = shopCartList;
        GridView1.DataBind();
       // GridView1.DataKeyNames = new String[] { "isbn" };

        //计算购物车物品总价格
        int sumPrice = 0;
        for (int i = 0; i < shopCartList.Count; i++)
            sumPrice += (((shopObject)shopCartList[i]).Cpdj * ((shopObject)shopCartList[i]).Count);
        labSumPrice.Text = "购物车总价格为:" + sumPrice + "元";
    }


出错在这一行
 sumPrice += (((shopObject)shopCartList[i]).Cpdj * ((shopObject)shopCartList[i]).Count);

------解决方案--------------------
sumPrice += ((shopObject)shopCartList[i]).Cpdj * ((shopObject)shopCartList[i]).Count;
------解决方案--------------------
是Count()吧
------解决方案--------------------
这样不是更清晰点?
   int sumPrice = 0;
         for (int i = 0; i < shopCartList.Count; i++)
         {
             shopObject shop=(shopObject)shopCartList[i];
             sumPrice += (shop.Cpdj * shop.Count);
         }
------解决方案--------------------
看下这个 shopObject model类的Cpdj , Count属性
很明显是这两个属性类型有一个不是int,估计是 Cpdj的问题吧 产品点击?产品定价?
------解决方案--------------------
sumPrice += ((shopObject)shopCartList[i]).Cpdj * ((shopObject)shopCartList[i]).Count;