日期:2014-05-18  浏览次数:20482 次

gridview汇总问题


如图 我下面的代码有问题吗?为什么汇总不了  

C# code
Decimal mysum4 = 0;Decimal sum2=0;
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
           if (e.Row.RowType == DataControlRowType.DataRow)
        {

            if (!string.IsNullOrEmpty(e.Row.Cells[2].Text.ToString()) && e.Row.Cells[2].Text.ToString() != " ")
            {
                 sum2 += decimal.Parse(e.Row.Cells[2].Text.ToString());
                mysum4 = mysum4 + sum2;
            }
         }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            e.Row.Cells[0].Text = "<span align='center' style='color:red'>合计:</span>";                      e.Row.Cells[2].Text = "<span align='center' style='color:red'>" + mysum4.ToString() + "</span>";
         }
}






------解决方案--------------------
探讨
如图 我下面的代码有问题吗?为什么汇总不了

C# code
Decimal mysum4 = 0;Decimal sum2=0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

if (e.Row.RowType == DataControlRowTy……

------解决方案--------------------
C# code

if (e.Row.RowIndex >= 0)
            {
                string xxx = e.Row.Cells[3].Text;
                sum += Convert.ToDouble(e.Row.Cells[3].Text);
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.Cells[2].Text = "总计:";
                e.Row.Cells[3].Text = sum.ToString();
               

            }