DataGrid的ShowFooter设置为true。我想实现每一页数据汇总。但是当我点击AspNetPager下一页的时候汇总结果是这一页数据的2倍。比如应该是42,结果变成84.为什么???
以下是我汇总的代码:public double numberTotal = 0;
public double costTotal = 0;
private void NumberTotal(string _number)
{
try
{
numberTotal +=Double.Parse(_number);
}
catch(Exception ex)
{
//捕获错误
Response.Write(ex.ToString());
}
}
private void CostTotal(string _cost)
{
try
{
costTotal += Double.Parse(_cost);
}
catch(Exception ex)
{
//捕获错误
Response.Write(ex.ToString());
}
}private void DataGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{ NumberTotal( e.Item.Cells[3].Text );
e.Item.Cells[3].Text =Convert.ToString(Convert.ToDouble(e.Item.Cells[3].Text));
CostTotal( e.Item.Cells[5].Text);
e.Item.Cells[5].Text=string.Format("{0:c}",Convert.ToDouble(e.Item.Cells[5].Text));
}
else if(e.Item.ItemType == ListItemType.Footer)
{
e.Item.Cells[0].Text="合计";
e.Item.Cells[3].Text = Convert.ToString(numberTotal);
e.Item.Cells[5].Text = string.Format("{0:c}", costTotal);
}