protected void gvorderinfo_RowDataBound(object sender, GridViewRowEventArgs e)
{
orderItemList OI = new orderItemList();
OI.Total = Convert.ToDecimal( Convert.ToDecimal((e.Row.Cells[2].Text)) * (Convert.ToDecimal((e.Row.Cells[3].Text))));
if (e.Row.RowIndex >= 0)
{
sum += Convert.ToDecimal(e.Row.Cells[4].Text);
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[3].Text = "总计:";
e.Row.Cells[4].Text = sum.ToString();
}
if (e.Row.RowIndex != -1)
{
int id = e.Row.RowIndex + 1;
e.Row.Cells[0].Text = id.ToString();
}
}
这段代码中的 “OI.Total = Convert.ToDecimal( Convert.ToDecimal((e.Row.Cells[2].Text)) * (Convert.ToDecimal((e.Row.Cells[3].Text))));”提示说“输入的字符串格式不正确”,错误出在哪儿了呢?
{
orderItemList OI = new orderItemList();
OI.Total = Convert.ToDecimal( Convert.ToDecimal((e.Row.Cells[2].Text)) * (Convert.ToDecimal((e.Row.Cells[3].Text))));
if (e.Row.RowIndex >= 0)
{
sum += Convert.ToDecimal(e.Row.Cells[4].Text);
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[3].Text = "总计:";
e.Row.Cells[4].Text = sum.ToString();
}
if (e.Row.RowIndex != -1)
{
int id = e.Row.RowIndex + 1;
e.Row.Cells[0].Text = id.ToString();
}
}
这段代码中的 “OI.Total = Convert.ToDecimal( Convert.ToDecimal((e.Row.Cells[2].Text)) * (Convert.ToDecimal((e.Row.Cells[3].Text))));”提示说“输入的字符串格式不正确”,错误出在哪儿了呢?
楼主应该是猎取 的数据有数字以外的字符。
OI.Total = Convert.ToDecimal(e.Row.Cells[2].Text.Trim()) * Convert.ToDecimal(e.Row.Cells[3].Text.Trim())
难道OI.Total的类型不是decimal类型吗?按道理不会出错的,我这边都可以运行过去,你报什么错误,不会是你的e.Row.Cells[2].Text或则e.Row.Cells[3].Text里面的数据有非法字符不能转换成decimal类型,你检查一下吧
{
private string productname;
public string ProductName
{
set { productname = value; }
get { return productname; }
}
private int productnum;
public int ProductNum
{
set { productnum=value;}
get { return productnum; }
}
private decimal price;
public decimal Price
{
set { price = value; }
get { return price; }
}
private decimal total;
public decimal Total
{
set { total = value; }
get { return total; }
}
public orderItemList()
{
}
public orderItemList(string ProductName, int ProductNum, decimal Price)
{
this.productname = ProductName;
this.productnum = ProductNum;
this.price = Price;
this.total = Total;
}
}
你看看,有什么类型不对应的吗?
{
this.productname = ProductName;
this.productnum = ProductNum;
this.price = Price;
this.total = Total;
} 你这句有问题啊
public orderItemList(string ProductName, int ProductNum, decimal Price,decimal Total)
{
this.productname = ProductName;
this.productnum = ProductNum;
this.price = Price;
this.total = Total;
}
参数掉了而且你的命名很不规范啊,你的参数和属性的名字都相同了,你改改吧,建议看看编码规范,简单的问题你自己好好检查,这样才能提高