本文介绍了计算网格视图中所有页面的页脚总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我有问题,我所拥有的3 col的总数将单独计算每个页面时,我需要使用gridview计算所有页面的总数而不是每个页面
正如你在代码中看到的那样我有3个col,他们每个人都有总数,但是当我启用分页时,它给我每个页面的总数,我需要所有页面的总数
thx ...
我的尝试:
hello, i have problem that the total for 3 col that i have will calculate every page alone when, i need to calculate the total for all pages not every page alone using gridview
as u see in code blow i have 3 col, everyone of them will have total but in when i enable paging its give me total for every page and i need total for all pages
thx...
What I have tried:
int RENT = 0;
int AMOUNTLEFT = 0;
int AMOUNTPAID = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
RENT += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "RENT"));
AMOUNTLEFT += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, " AMOUNTLEFT"));
AMOUNTPAID += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, " AMOUNTPAID"));
}
// Display totals in the gridview footer
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[14].Text = "Grand Total المجموع :-";
e.Row.Cells[14].Font.Bold = true;
e.Row.Cells[16].Text = AMOUNTPAID.ToString();
e.Row.Cells[16].Font.Bold = true;
e.Row.Cells[17].Text = RENT.ToString();
e.Row.Cells[17].Font.Bold = true;
e.Row.Cells[15].Text = AMOUNTLEFT.ToString();
e.Row.Cells[15].Font.Bold = true;
}
}
推荐答案
if (e.Row.RowType == DataControlRowType.Footer)
{
DataTable dt = GridView1.DataSource as DataTable;
int RENT = 0;
int AMOUNTLEFT = 0;
int AMOUNTPAID = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
RENT += Convert.ToInt32(dt.Rows[i]["RentColumnName"]);
AMOUNTLEFT += Convert.ToInt32(dt.Rows[i]["AMOUNTLEFTColumnName"]);
AMOUNTPAID += Convert.ToInt32(dt.Rows[i]["AMOUNTPAIDColumnName"]);
}
e.Row.Cells[14].Text = "Grand Total المجموع :-";
e.Row.Cells[14].Font.Bold = true;
e.Row.Cells[16].Text = AMOUNTPAID.ToString();
e.Row.Cells[16].Font.Bold = true;
e.Row.Cells[17].Text = RENT.ToString();
e.Row.Cells[17].Font.Bold = true;
e.Row.Cells[15].Text = AMOUNTLEFT.ToString();
e.Row.Cells[15].Font.Bold = true;
}
这篇关于计算网格视图中所有页面的页脚总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!