点击girdview中的编辑按钮就会报错:输入字符串的格式不正确。
问题描述:
————————————————————————————————
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int i;
for (i = 0; i < GridView1.Rows.Count; i++)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}
}
protected void GridView1_DataBound(object sender, EventArgs e)
{
double value = 0;
foreach(GridViewRow row in GridView1.Rows)
{
double price = Convert.ToDouble(row.Cells[3].Text);
int count = Convert.ToInt32(row.Cells[5].Text);
value += price * count;
}
GridViewRow footer = GridView1.FooterRow;
footer.Cells[0].ColumnSpan = 5;
footer.Cells[0].HorizontalAlign = HorizontalAlign.Center;
footer.Cells.RemoveAt(4);
footer.Cells[0].Text = "库存总价为(元):" + value;
以上是我的代码,报错在 double price = Convert.ToDouble(row.Cells[3].Text);这句上,
答
不应该写成Convert.ToDecimal(row.Cells[3].Text)这样吗?
参考Decimal,Money字段类型的区别:https://www.cnblogs.com/EasonJim/p/4837079.html