gridview查询出来了比如: 1  分角色读   121
 2  三对发生   234
 3  双方大啊   125现在的话我要把第三列的数字加起来 就是121和234和125加起来
然后出现第四行中,第四行,前面两列为空,就第三例是三者的和
 1  分角色读   121
 2  三对发生   234
 3  双方大啊   125
               480
请问这第四行怎么搞 谢谢

解决方案 »

  1.   


    第0列    第1列    第2列    第3列   第4列   第5列  
    -------------------------------------------
    班级     姓名     语文     数学    外语    (合计) 
    一班     小明     80      90     85     (255) 
    一班     小刚     85      88     90     (263) 
    一班     小涛     90      70     80     (240) 在GridView的RowDataBound事件里写如下代码:
    if(e.Row.RowType==DataControlRowType.DataRow)
    {
        string yuwen=DataBinder.Eval(e.Row.DataItem, "语文").ToString();
        string shuxue=DataBinder.Eval(e.Row.DataItem, "数学").ToString();
        string waiyu=DataBinder.Eval(e.Row.DataItem, "外语").ToString();
        Int sum=Convert.ToInt32(yuwen)+Convert.ToInt32(shuxue)+Convert.ToInt32(waiyu);
        string strSum=sum.tostring();
        e.Row.Cells[5].Text=strSum;
    }
      

  2.   

    if(e.Row.RowType==DataControlRowType.DataRow)
    {
        string yuwen=DataBinder.Eval(e.Row.DataItem, "语文").ToString();
        string shuxue=DataBinder.Eval(e.Row.DataItem, "数学").ToString();
        string waiyu=DataBinder.Eval(e.Row.DataItem, "外语").ToString();
        Int sum=Convert.ToInt32(yuwen)+Convert.ToInt32(shuxue)+Convert.ToInt32(waiyu);
        string strSum=sum.tostring();
        e.Row.Cells[5].Text=strSum;
    }
      

  3.   

    在查询sql语句中  添加一行数据:null,null,sum(合计) 然后直接绑定到gridview就行咯
      

  4.   

    select 字段1,字段2,字段3 from 表
    union
    select '','',sum(字段3) from 表
    order by 字段3
      

  5.   


    专门用一条sql语句,sum(.....)
      

  6.   

    不用sql语句,直接靠获取gridview的值然后加起来  e.row.cells是横加啊,竖加呢?
      

  7.   

    protected int sum;//合计 ,全局变量 
    //合计列
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
     // 合计
    if(e.Row.RowType==DataControlRowType.DataRow)
    {
       sum+=int.parse(e.Row.Cells[2].Text);
    }
                if (e.Row.RowType == DataControlRowType.Footer)
                {
                    e.Row.Cells[2].Text = "合计:";
                    e.Row.Cells[3].Text = sum.toString();
                }
    }
      

  8.   

        //定义一个变量 
        int count = 0;
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItemIndex == -1)
            {
                return;
            }
            count += e.Row.Cells[3].Text;
        }
      

  9.   

    从数据库中读取,绑定到GridView上