获取gridview单元格的总和不包括最后一个单元格

时间:2013-04-28 21:56:33

标签: c# asp.net

我正在尝试获取单元格的总和来查找订单总数。这是我的代码

  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();



        }

它工作正常,但它不会添加最后一个单元格

1 个答案:

答案 0 :(得分:0)

尝试使用小于或等于; &lt; =而不是&lt;

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

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

            }