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))));”提示说“输入的字符串格式不正确”,错误出在哪儿了呢?

解决方案 »

  1.   

    楼上也太过份了吧 !
    楼主应该是猎取 的数据有数字以外的字符。
    OI.Total = Convert.ToDecimal(e.Row.Cells[2].Text.Trim()) * Convert.ToDecimal(e.Row.Cells[3].Text.Trim()) 
      

  2.   

    OI.Total = Convert.ToDecimal( Convert.ToDecimal((e.Row.Cells[2].Text)) * (Convert.ToDecimal((e.Row.Cells[3].Text)))).ToString();
      

  3.   

    你的错误在于不能把decimal型转化为string型
      

  4.   

    OI.Total = (Convert.ToDecimal(e.Row.Cells[2].Text))*(Convert.ToDecimal(e.Row.Cells[3].Text));试试吧
      

  5.   


    难道OI.Total的类型不是decimal类型吗?按道理不会出错的,我这边都可以运行过去,你报什么错误,不会是你的e.Row.Cells[2].Text或则e.Row.Cells[3].Text里面的数据有非法字符不能转换成decimal类型,你检查一下吧
      

  6.   

     public class orderItemList
            {
                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;
                }
            }
    你看看,有什么类型不对应的吗?
      

  7.   

      public orderItemList(string ProductName, int ProductNum, decimal Price)
                {
                    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;
                } 
    参数掉了而且你的命名很不规范啊,你的参数和属性的名字都相同了,你改改吧,建议看看编码规范,简单的问题你自己好好检查,这样才能提高
      

  8.   

    上面说错了 你这Total 不需要放在构造函数里面, 你吧this.total = Total;去掉吧,我上面加的那个参数也不要
      

  9.   

    你查看下数据库中price和total是否有不是decimal类型的字符存在
      

  10.   

    我的数据不是存在数据库中的,而是存在list集合中的