在项模板内,包含有列:数量 单价
我希望在FooterTemplate内,绑定SUM(数量) SUM(单价)
应该怎么做啊?

解决方案 »

  1.   


    Public float Sum = 100;//在.cs里声明公共变量
    //然后在FooterTemplate
    <%=Sum.ToString()%>
      

  2.   

    如果只绑定一次就跟<ItemTemplate>里面一样
      

  3.   

     public void Bindcart()
            {
                int countpro = 0;
                decimal totalprice = 0;
              DataTable  dt = bllshop.GetList("userid=" + userid + " order by cartid desc").Tables[0]; 
    //获得datatable的方法
                if (dt.Rows.Count >0)
                {
                    
                    foreach (DataRow rw in dt.Rows)
                    {
                       //循环给数量和单价相加
                        countpro += Convert.ToInt32(rw["num"]);//数量
                        totalprice += Convert.ToInt32(rw["num"]) * Convert.ToDecimal(rw["price"]);          //总价=单价*数量        
                    } 
                   
                }
                Rpshopcart.DataSource = dt;
                Rpshopcart.DataBind();       //绑定数据
                Totalpros.Text = countpro.ToString();//在FooterTemplate里放两个label控件。
                totalprices.Text = totalprice.ToString();//取得总价格、总数量
                
            }
    大概的就是这样了。
      

  4.   

    需要配合ViewState保持状态。自我学习记录~