protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        int total=12;//总金额
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            total =total+ Convert.ToInt32( DataBinder.Eval(e.Row.DataItem, "ck_total"));        }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            e.Row.Cells[0].Text = "总金额:";
            e.Row.Cells[1].Text = total.ToString("c");
        }
    }
这怎么不行呢???
中间那块直接跳过去没有执行,在gridview中只显示12怎么不能统计呢?/

解决方案 »

  1.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            int total=12;//总金额
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                total =total+ Convert.ToInt32(e.Row.Cells["gridview统计的列名"].Text.Trim()));//Cells["gridview统计的列名"]也可以改为Cells[gridview统计的列号]        }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.Cells[0].Text = "总金额:";
                e.Row.Cells[1].Text = total.ToString("c");
            }
        }
      

  2.   

    请高手帮忙指点一二!!!怎么样才能更好的实现在gridview中实现列的求和
      

  3.   

    if( Convert.ToString( ((DataRowView)e.Item.DataItem)["ck_total"]) != string.Empty)
    {
    total =total+ Convert.ToInt32(((DataRowView)e.Item.DataItem)["ck_total"]);

    }
    这样只能计算本页的合计