日期:2014-05-19  浏览次数:20641 次

看看这段代码那里有问题.谢谢!!!!!!
提示格式有错误。应该怎么改啊!
  if   (e.Row.RowIndex   > =   0)
                {

                        sum   +=   Convert.ToInt32(e.Row.Cells[8].Text);
                        sum1   +=   Convert.ToInt32(e.Row.Cells[9].Text);
                }
                else   if   (e.Row.RowType   ==   DataControlRowType.Footer)
                {
                        e.Row.Cells[5].Text   =   "总数量为: ";
                        e.Row.Cells[6].Text   =   sum.ToString();
                        e.Row.Cells[3].Text   =   "平均价格为: ";
                        e.Row.Cells[4].Text   =   ((int)(sum1   /                 GridView1.Rows.Count)).ToString();

                }

------解决方案--------------------
if (e.Row.RowIndex > = 0 && e.Row.RowType != DataControlRowType.Footer)
------解决方案--------------------
我想是下面这两句产生的问题

Convert.ToInt32(e.Row.Cells[8].Text);
Convert.ToInt32(e.Row.Cells[9].Text);

e.Row.Cells[x].Text 有可能是空值或其它值么,如果有此情况,你的操作就有严重的问题了
可以使用 int.tryparse 直行转换,根据结果做相关的处理

程序应该就没有问题了


------解决方案--------------------
没有问题
------解决方案--------------------
强行转换格式前,最好先判断一下类型,要不就try,catch捕捉错误,要不很容易黄页
------解决方案--------------------
GridView1.Rows.Count 不会为0吧
------解决方案--------------------
把两个判断的次序更换一下