第四章 网页计算器
(1)前台页面设计:
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
(2)预览效果:
(3)后台代码编写:
try
{
double a = Convert.ToDouble(TextBox1.Text);
double b = Convert.ToDouble(TextBox2.Text);
if (DropDownList1.SelectedValue == "加")
{
Label1.Text = Convert.ToString(a + b);
}
else if (DropDownList1.SelectedValue == "减")
{
Label1.Text = Convert.ToString(a - b);
}
else if (DropDownList1.SelectedValue == "乘")
{
Label1.Text = Convert.ToString(a * b);
}
else if (DropDownList1.SelectedValue == "除")
{
if (b != 0)
{
Label1.Text = Convert.ToString(a / b);
}
else
{
Label1.Text = "不能除以0";
}
}
}
catch
{
Label1.Text = "请输入数字";
}
(4)验证成功!
转载于:https://blog.51cto.com/caohongjiang/324864