输入字符串的格式不正确,即使我有正确的值

Input string was not in a correct format even i have the right values in it

我有一个购物车网站。然而,当我提交 "submit order button" 它给我一个错误,说输入字符串的格式不正确。下面,我有声明变量的代码。

public class ShoppingCart
{
    public string CategoryName;
    public int CategoryID;
    public int ProductID;
    public int CustomerID;

    public string ProductName;
    public string ProductImage;
    public string ProductPrice;
    public string ProductDescription;
    public int ProductQuantity;

    public string BankDepositImage;

    public string CustomerName;
    public string CustomerEmailID;
    public string CustomerPhoneNo;
    public string CustomerAddress;
    public string ProductList;
    public string PaymentMethod;

    public string OrderStatus;
    public string OrderNo;

    public int TotalProducts;
    public int TotalPrice;
    public int StockType;
    public int Flag;

此代码中是我的文本框。

ShoppingCart k = new ShoppingCart()
            {
                CustomerName = txtCustomerName.Text,
                CustomerEmailID = txtCustomerEmailID.Text,
                CustomerAddress = txtCustomerAddress.Text,
                CustomerPhoneNo = txtCustomerPhoneNo.Text,
                TotalProducts = Convert.ToInt32(txtTotalProducts.Text),
                TotalPrice = Convert.ToInt32(txtTotalPrice.Text),
                ProductList = productids,
                PaymentMethod = rblPaymentMethod.SelectedItem.Text

            };

我在 shopping k = new shopping cart 代码行中收到一个错误。我对我在每个文本框中输入正确值的问题感到困惑。请谢谢

尝试使用 Int32.Parse

TotalPrice = Int32.Parse(txtTotalProducts.Text) 

正如史蒂夫建议的那样,确保输入没有小数。