
[英]Input string was not in a correct format. however I dont have string data
[英]Input string was not in a correct format even i have the right values in it
我有一个购物车网站。 然而,当我提交“提交订单按钮”时,它给了我一个错误,说输入字符串的格式不正确。 下面,我有我声明变量的代码。
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
};
我在购物 k = 新购物车代码行中收到一个错误。 我对问题是什么感到困惑,因为我在每个文本框中输入了正确的值。 谢谢,麻烦您了
尝试使用 Int32.Parse
TotalPrice = Int32.Parse(txtTotalProducts.Text)
正如史蒂夫所建议的,确保输入没有小数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.