【发布时间】:2014-03-11 23:01:32
【问题描述】:
基本上,我正在尝试获取一个复选框列表,以便能够为发票的“各种费用”选择几个不同的选项。 到目前为止,一切都成功了,但是我无法选择多个费用而不导致页面崩溃。
这是一个应有的示例:http://aspnet.cob.ohio.edu/matta/asppub/MIS3200/Unit4/BobcatU4L22.aspx
这是我当前的代码:
if (cblFees.Items[0].Selected)
{
decFees = decFees + Convert.ToDecimal(cblFees.Items[0].Value);
}
if (cblFees.Items[1].Selected)
{
decFees = decFees + Convert.ToDecimal(cblFees.Items[1].Value);
}
if (cblFees.Items[2].Selected)
{
decFees = decFees + Convert.ToDecimal(cblFees.Items[2].Value);
}
if (cblFees.Items[3].Selected)
{
decFees = decFees + Convert.ToDecimal(cblFees.Items[3].Value);
}
if (cblFees.Items[4].Selected)
{
decFees = decFees + Convert.ToDecimal(cblFees.Items[4].Value);
}
if (decStateTaxRate == 0.00M)
{
lblOutputCheckBoxList.Visible = true;
lblOutputCheckBoxList.Text = "The State Code was not recognized.";
}
if (decStateTaxRate > 0.00M)
{
decCalculatedStateTax = (decStateTaxRate * decSales);
decTotalDue = (decCalculatedStateTax + decSales);
lblOutputCheckBoxList.Visible = true;
lblOutputCheckBoxList.Text = "Your state is: " + strState + "<br />" + " the tax rate is " + decStateTaxRate + "<br />" +
"Sales Tax = " + decCalculatedStateTax.ToString("C2") + "<br />" + "Fees (after sales tax) = " + decFees + "<br />" + "Total Due = " + decTotalDue.ToString("C2");
}
Server Error in '/asppub' Application. Input string was not in a correct format. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more关于错误的信息以及它在代码中的来源。
Exception Details: System.FormatException: Input string was not in a correct format. Source Error: Line 177: if (cblFees.Items[0].Selected) Line 178: { Line 179: decFees = decFees + Convert.ToDecimal(cblFees.Items[0].Value); Line 180: } Line 181: if (cblFees.Items[1].Selected) Source File: c:\Users\Ryan\Desktop\asppub\MIS3200\Unit4\RingU4L2.2.aspx.cs Line:179
Stack Trace: [FormatException: Input string was not in a correct format.] System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)+9594763 System.Number.ParseDecimal(字符串值,NumberStyles 选项,NumberFormatInfo numfmt)+146 System.Convert.ToDecimal(字符串值)+68 MIS3200_Unit4_RingU4L1.btnCheckBox_Click(Object sender, EventArgs e) in c:\Users\Ryan\Desktop\asppub\MIS3200\Unit4\RingU4L2.2.aspx.cs:179 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118 System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串 eventArgument)+112 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串 事件参数)+10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(布尔型 includeStagesBeforeAsyncPoint,布尔型 includeStagesAfterAsyncPoint) +5563
【问题讨论】:
-
您得到的错误究竟是什么? “页面崩溃”不是很有帮助。
-
在此处放置尝试、捕获并粘贴错误,以便我们了解确切的问题。
-
我猜页面真的崩溃了
-
问题是下面的值不能转换成小数:
cblFees.Items[0].Value。要回答您的问题,如果您检查调试器中的值并在此处发布其内容,将会很有帮助。通常,这些问题与文化设置有关。
标签: c# asp.net checkboxlist