现在的位置: 首页 > 综合 > 正文

GridView求整行数据的相加和

2013年06月24日 ⁄ 综合 ⁄ 共 608字 ⁄ 字号 评论关闭

今天本来想求列的和,没想到阴差阳错的把行的和搞出来了,先把求行的和贴出来 随后再贴列的和。

table = doe.GetCommodity_Retail_List_dtl();

   //------------------------------------------------------------//
        table.Columns.Add("Sum", typeof(Int32));                      //增加列
        int sum = 0;
        foreach (DataRow dr in table.Rows)               //循环计算综合
        {
            if (dr["price"].ToString().Length == 0)
                continue;
            sum += int.Parse(dr["price"].ToString());
        }
        foreach (DataRow dr in table.Rows)           //计算后结果赋值给新增的列
        {
            dr["Sum"] = sum;
        }
        //------------------------------------------------------------//

抱歉!评论已关闭.