我正在使用asp.net网格视图,我有一列,即Calories,我想在顶部显示整个caloreis总数。我使用了以下代码:
int count = grdViewSample.Rows.Count;
double totCalories = 0;
Label lblCalories = new Label();
foreach (GridViewRow row in grdViewSample.Rows)
{
lblCalories = (Label)row.FindControl("lblCalories");
totCalories = totCalories + Convert.ToDouble(lblCalories.Text);
}
lblTotalCaloreis.Text = lblTotalCaloreis.Text + " " + totCalories;
我的问题是通过分页改变了卡路里总量,我想要在网格视图中可用的总卡路里。 感谢
答案 0 :(得分:0)
Instated of using
grid view row property retrive no of rows from the data set directly because row property changes with the paging
foreach (DataRow row in dsFood.Tables[0].Rows)
{
totCal += Convert.ToDouble(row["calories"]);
}
lblCalories.Text = " " + totCal;