mad*_*dan 0 c# asp.net webforms
我是.Net的新手.这可能是一个愚蠢的问题,但请耐心等待.我不知道出了什么问题,但服务器脚本中的'if'语句被绕过了.我使用网页表格.你能告诉我一个解决方案吗?
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void btnCalculate_Click(object sender, EventArgs e)
{
int price = 0;
int fee = Convert.ToInt32(ddlCourses.SelectedItem.Value);
price += fee;
if (rbMorning.Checked || rbAfternoon.Checked)
price -= fee * (10 / 100);
if (cbMaterial.Checked)
price += fee * (10 / 100);
lblMsg.Text = "Total Fee: " + price;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>CoursesApp 1.0</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Courses Application</h3>
<br />
<asp:DropDownList ID="ddlCourses" runat="server">
<asp:ListItem Value="3000">Java SE</asp:ListItem>
<asp:ListItem Value="4500">Java EE</asp:ListItem>
<asp:ListItem Value="6000">.Net</asp:ListItem>
<asp:ListItem Value="3000">Oracle DB</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:RadioButton ID="rbMorning" runat="server" Text="Morning" Checked="True" GroupName="timing" />
<asp:RadioButton ID="rbAfternoon" runat="server" Text="Afternoon" GroupName="timing" />
<asp:RadioButton ID="rbEvening" runat="server" Text="Evening" GroupName="timing" />
<br />
<br />
<asp:CheckBox ID="cbMaterial" runat="server" Text="Material" />
<br />
<br />
<asp:Button ID="btnCalculate" runat="server" OnClick="btnCalculate_Click" Text="Calculate" />
<br />
<br />
<asp:Label ID="lblMsg" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
问题:0当你分开时你的表达总是如此(10/100),当与费用相乘时,它将再次为零,因此不会发生减法或加法.
解决方案:你需要multiply使用feewith 10然后divide通过它100.
试试这个:
if (rbMorning.Checked || rbAfternoon.Checked)
price -= (10 * fee / 100);
if (cbMaterial.Checked)
price += (10 * fee / 100);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
126 次 |
| 最近记录: |