gridview 增加行,进行数据汇总

DataRow dr  =  table1.NewRow();
          
// 1是把所有列进行汇总
           
// for (int i = 1; i < table1.Columns.Count; i++)
           
//  {
               
//  dr = table1.Compute("Sum(" + table1.Columns.ColumnName + ")", "true");   
            
// }


           
// 仅对需要的列进行汇总
              decimal  xxx  =   0 ;
            
decimal  xxx1  =   0 ;
             
for  ( int  i  =   1 ; i  <  table1.Rows.Count; i ++ )
             
{
                 
                 xxx  
+= Convert.ToDecimal(table1.Rows["衣服用费"]);
                 dr[
1]=xxx;
                 
                 xxx1 
+= Convert.ToDecimal(table1.Rows["住宿费用"]);
                 dr[
2= xxx1;

            }


            table1.Rows.Add(dr);

            GridView1.DataSource 
=  table1;

你可能感兴趣的:(GridView)