在計算gridview單元格總數時,我得到以下例外: 輸入字符串格式不正確。計算GridView單元格總數時出現異常
這裏是我的代碼:任何幫助請:
public decimal GetTotal()
{
decimal total = 0;
foreach (GridViewRow _row in GridView1.Rows)
{
TextBox txt = (TextBox)_row.FindControl("TextBox1");
total +=decimal.Parse(txt.Text);
}
return total;
}
感謝您的回覆......這個問題解決了,但總不能計算,我打電話是::要做到這一點,沒有拋出異常,使用
TryParse
方法 如果( e.RowType == DataControlRowType.Footer) {TextBox txtTotalPrice =(TextBox)e.Row.FindControl(「total」); txtTotalPrice.Text = GetTotal()。ToString(); } – jims 2011-05-23 06:30:36