GridView求整行数据的相加和

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

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;
        }
        //------------------------------------------------------------//

原文地址:https://www.cnblogs.com/song_/p/3048719.html