我正在使用RowDataBound
Event 来计算列数据的总和。我得到列值总和的变量在rowdatabound
事件结束时变为零,因为它的初始值为零。如何将值的总和存储在变量中以在事件之外使用其值。谢谢
int totSubTot = 0;
public double TotalAmount;
protected void gvShowOrder_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
totSubTot += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "SubTotal"));
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[2].Text = "Grand Total";
e.Row.Cells[2].Font.Bold = true;
e.Row.Cells[3].Text = totSubTot.ToString();
e.Row.Cells[3].Font.Bold = true;
TotalAmount = Convert.ToDouble(e.Row.Cells[3].Text);
}
}