GridView控件实现统计每一页数据 有关问题 求各位大神前辈们帮帮忙看看
GridView控件实现统计每一页数据 问题 求各位大神前辈们帮帮忙看看
求各位大神帮忙分析下这代码, 我想在GridView里面做一个统计每一页的资产价格和数量, 统计是没问题的,就是我在页面上如何在做一个查询语句时候,就会报错
输入字符串的格式不正确。
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.FormatException: 输入字符串的格式不正确。
行 145: break;
行 146: case DataControlRowType.DataRow:
行 147: _totalFreight += decimal.Parse(e.Row.Cells[5].Text);
行 148: shuliang += int.Parse(e.Row.Cells[8].Text);
行 149: _totalCount++;
decimal _totalFreight = 0m;
int _totalCount = 0;
int shuliang = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex > -1)
{
e.Row.Attributes.Add("onmouseover", "color=this.style.backgroundColor;this.style.background='#FFF9DD'; ");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=color;");
}
switch (e.Row.RowType)
{
case DataControlRowType.Header:
e.Row.Cells[0].Text = "编号";
e.Row.Cells[1].Text = "资产编号";
e.Row.Cells[2].Text = "资产名称";
e.Row.Cells[3].Text = "规格型号";
e.Row.Cells[4].Text = "领用时间";
e.Row.Cells[5].Text = "资产单价";
e.Row.Cells[6].Text = "借出人";
e.Row.Cells[7].Text = "领用部门";
e.Row.Cells[8].Text = "领用数量";
e.Row.Cells[9].Text = "资产类型";
break;
case DataControlRowType.DataRow:
_totalFreight += decimal.Parse(e.Row.Cells[5].Text);
shuliang += int.Parse(e.Row.Cells[8].Text);
_totalCount++;
break;
case DataControlRowType.Footer:
// 合計值的呈現
e.Row.Cells[0].Text = "合計";
e.Row.Cells[5].Text = _totalFreight.ToString();
e.Row.Cells[8].Text = shuliang.ToString();
shuliang = 0;
_totalFreight = 0;
_totalCount = 0;
break;
}
}
------解决思路----------------------
出错是因为用到了Decimal的Prase方法吧?类型转换失败就会报这个错误,可以判断下从数据库中查询出来的值是不是可以转换
------解决思路----------------------
查询绑定是你设置断点查看下面这两个地方,是否有数值?
_totalFreight += decimal.Parse(e.Row.Cells[5].Text);
shuliang += int.Parse(e.Row.Cells[8].Text);
没有或者不对的话改成下面的代码试试
DataRowView myrows=(DataRowView)e.Row.DataItem;
_totalFreight += decimal.Parse(myrows[5].ToString());
shuliang += int.Parse(myrows[8].ToString());
------解决思路----------------------
极大可能是你类型转换的地方出现错误了!!
断点一下看看是哪一句报错吧
------解决思路----------------------
你的SQL语句有问题啊 from前面多了个,
求各位大神帮忙分析下这代码, 我想在GridView里面做一个统计每一页的资产价格和数量, 统计是没问题的,就是我在页面上如何在做一个查询语句时候,就会报错
输入字符串的格式不正确。
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.FormatException: 输入字符串的格式不正确。
行 145: break;
行 146: case DataControlRowType.DataRow:
行 147: _totalFreight += decimal.Parse(e.Row.Cells[5].Text);
行 148: shuliang += int.Parse(e.Row.Cells[8].Text);
行 149: _totalCount++;
decimal _totalFreight = 0m;
int _totalCount = 0;
int shuliang = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex > -1)
{
e.Row.Attributes.Add("onmouseover", "color=this.style.backgroundColor;this.style.background='#FFF9DD'; ");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=color;");
}
switch (e.Row.RowType)
{
case DataControlRowType.Header:
e.Row.Cells[0].Text = "编号";
e.Row.Cells[1].Text = "资产编号";
e.Row.Cells[2].Text = "资产名称";
e.Row.Cells[3].Text = "规格型号";
e.Row.Cells[4].Text = "领用时间";
e.Row.Cells[5].Text = "资产单价";
e.Row.Cells[6].Text = "借出人";
e.Row.Cells[7].Text = "领用部门";
e.Row.Cells[8].Text = "领用数量";
e.Row.Cells[9].Text = "资产类型";
break;
case DataControlRowType.DataRow:
_totalFreight += decimal.Parse(e.Row.Cells[5].Text);
shuliang += int.Parse(e.Row.Cells[8].Text);
_totalCount++;
break;
case DataControlRowType.Footer:
// 合計值的呈現
e.Row.Cells[0].Text = "合計";
e.Row.Cells[5].Text = _totalFreight.ToString();
e.Row.Cells[8].Text = shuliang.ToString();
shuliang = 0;
_totalFreight = 0;
_totalCount = 0;
break;
}
}
------解决思路----------------------
出错是因为用到了Decimal的Prase方法吧?类型转换失败就会报这个错误,可以判断下从数据库中查询出来的值是不是可以转换
------解决思路----------------------
查询绑定是你设置断点查看下面这两个地方,是否有数值?
_totalFreight += decimal.Parse(e.Row.Cells[5].Text);
shuliang += int.Parse(e.Row.Cells[8].Text);
没有或者不对的话改成下面的代码试试
DataRowView myrows=(DataRowView)e.Row.DataItem;
_totalFreight += decimal.Parse(myrows[5].ToString());
shuliang += int.Parse(myrows[8].ToString());
------解决思路----------------------
极大可能是你类型转换的地方出现错误了!!
断点一下看看是哪一句报错吧
------解决思路----------------------
你的SQL语句有问题啊 from前面多了个,