datagrid footer 列出指定行之和

我的学习笔记

  1. ShowFooter="True"  
  2.   
  3.    
  4.   
  5. private double sum = 0;//取指定列的数据和,你要根据具体情况对待可能你要处理的是int  
  6.     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)  
  7.     {  
  8.           
  9.         if (e.Row.RowIndex >= 0)  
  10.         {  
  11.             sum += Convert.ToDouble(e.Row.Cells[5].Text)  
  12.         }  
  13.         if (e.Row.RowIndex >= 0)  
  14.         {  
  15.             sum += Convert.ToDouble(e.Row.Cells[5].Text);  
  16.         }  
  17.         else if (e.Row.RowType == DataControlRowType.Footer)  
  18.         {  
  19.             e.Row.Cells[4].Text = "总价格为:";  
  20.             e.Row.Cells[5].Text = sum.ToString();  
  21.             e.Row.Cells[2].Text = "平均价格为:";  
  22.             e.Row.Cells[3].Text = ((int)(sum / GridView1.Rows.Count)).ToString();  
  23.   
  24.         }  
  25.          

 

  1.     }  

 

我的笔记

 

   protected void gv_checkstatistics_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            TableCell cell = new TableCell();
            cell.ColumnSpan = e.Row.Cells.Count;
            cell.HorizontalAlign = HorizontalAlign.Right;
            e.Row.Cells.Clear();
            for (int i = 0; i < 7; i++)
            {
                e.Row.Cells.Add(new TableCell());
            }
            e.Row.Cells[1].Attributes.Add("colspan", "2");
            e.Row.Cells[1].Text = mysum1.ToString();
            e.Row.Cells[2].Attributes.Add("colspan", "2");
            e.Row.Cells[2].Text = mysum3.ToString();
            e.Row.Cells[3].Attributes.Add("colspan", "2");
            e.Row.Cells[3].Text = mysum5.ToString();
        
        }


        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DataRowView myrows = (DataRowView)e.Row.DataItem;
            if (!( + myrows[2].ToString() + myrows[2].ToString()).ToString().Contains('%'))
            {
                mysum1 += Convert.ToInt32(myrows[1].ToString()) + Convert.ToInt32(myrows[2].ToString());
                mysum3 += Convert.ToInt32(myrows[3].ToString()) + Convert.ToInt32(myrows[4].ToString());
                mysum5 += Convert.ToInt32(myrows[5].ToString()) + Convert.ToInt32(myrows[6].ToString());
            }
        }


    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我笔记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值