我想知道如何在gridview中显示各列的总和? [英] i want to know how can i show sum of individual columns in gridview?

查看:102
本文介绍了我想知道如何在gridview中显示各列的总和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gridview中有6列(salary,ta,contingency,nrc,institcharges,others)我想要的是我想得到每列页脚中每列的总和。为此,我已经采取了模板字段并在其中插入了一个标签,但我的问题在于我的编码结果我得到的是每个标签上所有列的总和



这是我在我的代码后面使用的代码:



i have 6 columns (salary,ta,contingency,nrc,institcharges,others) in my gridview what i wanna do is i want to get the sum of each column in the footer of each column. for this i have taken template fields and inserted a label in them but my problem is in my coding the result i am getting is total of all the columns on each label

this is the code i m using in my code behind file:

int total = 0;
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {



        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            total += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "salary"));
        }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label sallabel = (Label)e.Row.FindControl("sallabel");
            sallabel.Text = total.ToString();
        }

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            total += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "ta"));
        }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label lblamount2 = (Label)e.Row.FindControl("talabel");
            lblamount2.Text = total.ToString();

        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            total += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "contigency"));
        }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label lblamount3 = (Label)e.Row.FindControl("cnlabel");
            lblamount3.Text = total.ToString();
        }

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            total += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "nrc"));
        }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label lblamount4 = (Label)e.Row.FindControl("nrclabel");
            lblamount4.Text = total.ToString();

        }

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            total += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "institcharges"));
        }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label lblamount5 = (Label)e.Row.FindControl("iclabel");
            lblamount5.Text = total.ToString();
        }

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            total += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "others"));
        }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label lblamount6 = (Label)e.Row.FindControl("olabel");
            lblamount6.Text = total.ToString();
        }

    }

推荐答案

http://msdn.microsoft.com/en-us/library/ms972833.aspx [ ^ ]

http://stackoverflow.com/questions/12853406/how-to-diplay-boundfield-columns-values -sum-in-footer-row [ ^ ]

http://aspalliance.com/ 782_CodeSnip_How_to_Display_Sum_Total_in_the_Footer_of_the_GridView_Control [ ^ ]

http://techbrij.com/831/display-total-gridview-footer-row-linq-asp-net [ ^ ]
http://msdn.microsoft.com/en-us/library/ms972833.aspx[^]
http://stackoverflow.com/questions/12853406/how-to-diplay-boundfield-columns-values-sum-in-footer-row[^]
http://aspalliance.com/782_CodeSnip_How_to_Display_Sum_Total_in_the_Footer_of_the_GridView_Control[^]
http://techbrij.com/831/display-total-gridview-footer-row-linq-asp-net[^]


这篇关于我想知道如何在gridview中显示各列的总和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆