我有一個顯示一些值的網格視圖。現在我必須計算每行的這些值的行明智總和,然後顯示它們。如何在網格視圖中計算行的總和值並將其顯示在網格視圖中?
我試過這段代碼,但由於輸入字符串的格式不正確而出現錯誤。
public void gv_RowCreated(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int total = Convert.ToInt32(e.Row.Cells[1].Text) + Convert.ToInt32(e.Row.Cells[2].Text) + Convert.ToInt32(e.Row.Cells[3].Text) + Convert.ToInt32(e.Row.Cells[4].Text) + Convert.ToInt32(e.Row.Cells[5].Text) + Convert.ToInt32(e.Row.Cells[6].Text) + Convert.ToInt32(e.Row.Cells[7].Text);
((Label)gv.FindControl("Label8")).Text = Convert.ToString(total);
}
}
您能通過示例代碼解釋一下嗎? – 2011-03-14 09:21:35