gpt4 book ai didi

c# - 我不断收到 An exception of type 'System.InvalidCastException' occurred in mscorlib.dll but was not handled in user code for RetailPrice

转载 作者:太空宇宙 更新时间:2023-11-03 19:53:56 25 4
gpt4 key购买 nike

protected void btnCalculateOrder_Click(object sender, EventArgs e)
{
OrderSession();

if (IsValid)
{
double RetailPrice = Convert.ToDouble(lblRetailPrice);
double Quantity = Convert.ToDouble(txtQuantity);
double Tax = (.9);

double Subtotal = RetailPrice * Quantity;
double TotalAmount = Subtotal + Tax;

lblSubTotal.Text = Subtotal.ToString("c");
lblTotalAmount.Text = TotalAmount.ToString("c");
}

}

最佳答案

吹毛求疵,你不需要支架:

double Tax = (.9); //change to double Tax = .9; or double Tax = 0.9;

问题:

似乎您想Convert Controls 而不是ControlsText

double RetailPrice = Convert.ToDouble(lblRetailPrice); //I assume this is a Label Control
double Quantity = Convert.ToDouble(txtQuantity); //and this is a TextBox Control

尝试将它们更改为:

double RetailPrice = Convert.ToDouble(lblRetailPrice.Text);
double Quantity = Convert.ToDouble(txtQuantity.Text);

关于c# - 我不断收到 An exception of type 'System.InvalidCastException' occurred in mscorlib.dll but was not handled in user code for RetailPrice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35762106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com