2013-04-28 105 views
-1

我正在嘗試獲取單元格的總和以查找總額。這裏是我的代碼獲取gridview單元格的總和不包括最後一個單元格

protected void OrdelistDetails_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 

     if (e.Row.RowType == DataControlRowType.DataRow) 
     { 

      decimal sum = 0; 

      for (int i = 0; i < OrdelistDetails.Rows.Count; ++i) 
      { 

       sum += Convert.ToDecimal((OrdelistDetails.Rows[i].FindControl("lblitemTotal") as Label).Text); 

      } 

      lblTotal.Text = sum.ToString(); 



     } 

它工作正常,但它不添加的最後一個單元格

+0

你可以嘗試設置斷點事件和檢查多少行存在於網格? – Steve 2013-04-28 22:16:56

回答

0

嘗試使用小於或等於; < =代替<

for (int i = 0; i <= OrdelistDetails.Rows.Count; ++i) 
      { 

       sum += Convert.ToDecimal((OrdelistDetails.Rows[i].FindControl("lblitemTotal") as Label).Text); 

      } 
+0

仍然無法正常工作.. – 2013-04-28 22:07:56

相關問題