同尾行总的GridView网格的最后一页 [英] gridview with footer row total in the final page of the grid

查看:157
本文介绍了同尾行总的GridView网格的最后一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void inderGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            decimal rowTotal = Convert.ToDecimal
            (DataBinder.Eval(e.Row.DataItem, "DC_No_Decimal"));
            //grdTotal = grdTotal + rowTotal;
            grdTotal += rowTotal;
        }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label lbl = (Label)e.Row.FindControl("lblTotal");
            e.Row.Cells[3].Text = grdTotal.ToString("c");
            //lbl.Text = grdTotal.ToString("c");
        }       
    }

从上面的code I M在网格视图中的每个页面获得总。相反,总让每一页的我需要的所有页共在网格视图页脚的结束。立刻帮助。
在此先感谢

from the above code i m getting total for every page in the grid view. Instead of getting total to every page i need all page total at the end of the grid view footer. Help Immediatly. Thanks in advance

推荐答案

如果你想总的全部的网页,并为页脚只出现在最后一页上,那么你就不能就算你是怎么做的总数。

If you want the total of ALL pages, and for the footer to only appear on the last page, then you can't calculate the totals how you are doing.

目前,您通过GridView的每一行循环。如果您正在使用分页GridView控件将不被显示的所有行,所以总不会是正确的。

At the moment your looping through every row on the gridview. If you are using paging the gridview won't be showing all the rows, so the total won't be correct.

您具有分页功能的 PagedDataSource 或你限制记录从SQL等回来?如果您使用的是的DataSet PagedDataSource 你就可以找到从DataSet总(因为这将包含所有的记录)。否则,你必须创建第二个查询来计算总。

Are you paging with a PagedDataSource or are you limiting the records returned from SQL etc? If you are using a DataSet and a PagedDataSource you'll be able to find the total from the DataSet (as this will contain all the records). Otherwise, you'll have to create a second query to calculate the total.

然后在显示在页脚的价值观方面,你就会有一个如果语句添加到您的的ItemDataBound 事件仅当它的最后一页显示这一点。

Then in terms of displaying the values in the footer, you'll have to add an IF statement to your ItemDataBound event to only display this if its the final page.

这篇关于同尾行总的GridView网格的最后一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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