我收到此錯誤「異常詳細信息:System.FormatException:輸入字符串的格式不正確。」看來我的轉換和解析不起作用。我使用ASP.NET C#。還有一種方法只是讀取數字值而不是使用文本框?異常詳細信息:System.FormatException:輸入字符串格式不正確。解析不起作用
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="Payroll" runat="server">
<div>
<h1>Exception Painting</h1>
<h2>Payroll Calculator</h2>
<p>Employee Name: <asp:TextBox ID="Name" runat="server"></asp:TextBox>
<p>Pay Rate: <asp:TextBox ID="PayRate" runat="server"></asp:TextBox>
<p>Salary Employee: <asp:TextBox ID="SalaryEmployee" runat="server"></asp:TextBox>
<p>Hours Worked: <asp:TextBox ID="HoursWorked" runat="server"></asp:TextBox>
<asp:Button ID="Submit" runat="server" Text="Submit" />
</div>
</form>
<%
double overtimeHours = 0;
double overtimePay = 0;
double regularPay = 0;
double totalPay = 0;
double regularHours = 0;
double basePay = 0;
double hrsWrked = 0;
double payRt = 0;
string nm = Name.Text;
hrsWrked = Convert.ToDouble(HoursWorked.Text);
//I cant figure out what im doing wrong here..
hrsWrked = double.Parse(HoursWorked.Text);
string slry = Name.Text;
payRt = Convert.ToDouble(PayRate.Text);
payRt = double.Parse(PayRate.Text);
double overtimePayRt = payRt * 1.5;
if (Page.IsPostBack)
{
Payroll.Visible = false;
if (SalaryEmployee.Equals("no") && hrsWrked > 40)
overtimeHours = hrsWrked - 40;
regularHours = hrsWrked - overtimeHours;
overtimePay = overtimeHours * overtimePayRt;
regularPay = payRt * regularHours;
totalPay = overtimePay + regularPay;
basePay = hrsWrked * 52 * totalPay;
Response.Write("Employee Name: " + nm + "Base Salary: " + basePay + "Hours Worked: " + hrsWrked + "Total Weekly Pay: " + totalPay);
if (SalaryEmployee.Equals("yes"))
regularHours = 40;
totalPay = payRt * regularHours;
basePay = hrsWrked * 52 * totalPay;
Response.Write("Employee Name: " + nm + "Base Salary: " + basePay + "Hours Worked: " + hrsWrked + "Total Weekly Pay: " + totalPay);
}
%>
</body>
</html>
只要我點擊調試,代碼就會運行!所以文本字段是空白的! – RadioSpace 2014-09-24 03:10:50