实现一个简易计算器

Calculator.aspx文件

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Calculator.aspx.cs" Inherits="Ex4_Calculator" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title></title>

</head>

<body>

<form id="form1" runat="server">

<div style="text-align:center">

<asp:TextBox ID="txtDisplay" runat="server" Width="110px" ReadOnly="True"></asp:TextBox><br />

<asp:Button ID="btnOne" runat="server" Text="1" Width="40px" Onclick="btnOne_Click"/>

<asp:Button ID="btnTwo" runat="server" Text="2" Width="40px" Onclick="btnTwo_Click"/>

<asp:Button ID="btnThree" runat="server" Text="3" Width="40px"  Onclick="btnThree_Click"/><br />

<asp:Button ID="btnAdd" runat="server" Text="+" Width="40px"  Onclick="btnAdd_Click"/>

<asp:Button ID="btnSubtract" runat="server" Text="-" Width="40px" Onclick="btnSubtract_Click" />

<asp:Button ID="btnEqual" runat="server" Text="=" Width="40px"  Onclick="btnEqual_Click"/>

</div>

</form>

</body>

</html>

Calculator.aspx.cs文件

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class Ex4_Calculator : System.Web.UI.Page

{

static string num1 = "0", num2 = "0", total = "", sign = "";

protected void Page_Load(object sender, EventArgs e)

{

}

protected void Count()

{

num2 = txtDisplay.Text;

if (num2 == "")

{

num2 = "0";

}

switch(sign)

{

case "+":

txtDisplay.Text = (int.Parse(num1) + int.Parse(num2).ToString() );

num1 = "0";

num2 = "0";

total = "";

sign = "";

break;

case "-":

txtDisplay.Text = (int.Parse(num1) - int.Parse(num2)).ToString();

num1 = "0";

num2 = "0";

total = "";

sign = "";

break;

}

}

protected void btnOne_Click(object sender, EventArgs e)

{

total += "1";

txtDisplay.Text = total;

}

protected void btnTwo_Click(object sender, EventArgs e)

{

total += "2";

txtDisplay.Text = total;

}

protected void btnThree_Click(object sender, EventArgs e)

{

total += "3";

txtDisplay.Text = total;

}

protected void btnAdd_Click(object sender, EventArgs e)

{

if (sign.Length == 1)

{

Count();

num1 = txtDisplay.Text;

sign = "+";

}

else

{

num1 = txtDisplay.Text;

txtDisplay.Text = "";

total = "";

sign = "+";

}

}

protected void btnSubtract_Click(object sender, EventArgs e)

{

if (sign.Length == 1)

{

Count();

num1 = txtDisplay.Text;

sign = "-";

}

else

{

num1 = txtDisplay.Text;

txtDisplay.Text = "";

total = "";

sign = "-";

}

}

protected void btnEqual_Click(object sender, EventArgs e)

{

Count();

}

}

实现下拉列表实验

Course.aspx文件

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Course.aspx.cs" Inherits="Course" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title></title>

</head>

<body>

<form id="form1" runat="server">

<p>

学年:<asp:DropDownList ID="ddlYear" runat="server" AutoPostBack="True">

</asp:DropDownList>

学期:<asp:DropDownList ID="ddlTerm" runat="server" AutoPostBack="True">

</asp:DropDownList>

分院:<asp:DropDownList ID="ddlCollege" runat="server" AutoPostBack="True" Width="120px" OnSelectedIndexChanged="ddlCollege_SelectedIndexChanged">

</asp:DropDownList>

教师<asp:DropDownList ID="ddlTeacher" runat="server" AutoPostBack="True">

</asp:DropDownList>

</p>

</form>

</body>

</html>

Course.aspx.cs文件

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class Course : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

BindYear();

BindTerm();

BindCollege();

BindTeache();

}

}

protected void BindYear()

{

ddlYear.Items.Clear();

int startYear = DateTime.Now.Year - 10;

int currentYear = DateTime.Now.Year;

for (int i = startYear; i <= currentYear; i++)

{

ddlYear.Items.Add(new ListItem((i-1).ToString()+ "-"+i.ToString()));

}

ddlYear.SelectedValue = (currentYear - 1).ToString() + "-" + currentYear.ToString();

}

protected void BindTerm()

{

ddlTerm.Items.Clear();

for (int i = 1; i <= 2; i++)

{

ddlTerm.Items.Add(i.ToString());

}

}

protected void BindCollege()

{

ddlCollege.Items.Clear();

ddlCollege.Items.Add(new ListItem("计算机学院"));

ddlCollege.Items.Add(new ListItem("外国语学院"));

ddlCollege.Items.Add(new ListItem("机电学院"));

}

protected void BindTeache()

{

ddlTeacher.Items.Clear();

switch (ddlCollege.SelectedValue)

{

case "计算机学院":

ddlTeacher.Items.Add(new ListItem("曹明"));

ddlTeacher.Items.Add(new ListItem("李妙"));

ddlTeacher.Items.Add(new ListItem("王芳"));

break;

case "外国语学院":

ddlTeacher.Items.Add(new ListItem("张强"));

ddlTeacher.Items.Add(new ListItem("王第男"));

break;

case "机电学院":

ddlTeacher.Items.Add(new ListItem("朱兆清"));

ddlTeacher.Items.Add(new ListItem("毛沁程"));

break;

}

}

protected void ddlCollege_SelectedIndexChanged(object sender, EventArgs e)

{

BindTeache();

}

}

ASP.NET实验Calculator Drop down list相关推荐

  1. ASP木马实验(I春秋)

    ASP木马实验(i 春秋) 传送门 https://www.ichunqiu.com/vm/483/1?source=1 首先进入分配好的实验环境 打开Chrome 在我的电脑中使用FTP链接服务器 ...

  2. linux上使用ASP

    最近作了一下linux 支持asp的实验.大部分质料是从google上搜的!!贴出来与大家一起学习. 一.iASP软件环境要求 iASP软件是用JAVA程序语言编制而成的,需要JDK1.1.X或以上版 ...

  3. Windows Mobile动手实验集锦

    Windows Mobile动手实验集锦 http://blog.csdn.net/zhangbosun/archive/2007/06/14/1652862.aspx 不过文章里提到的一些链接已经失 ...

  4. 计算机本科专业ASP项目

    本科计算机ASP毕业软件设计,有软件.PPT.论文, ASP学生公寓管理系统的设计与实现(源代码+论文).rar ASP学科建设设计(源代码+论文).rar ASP基于BS视频点播系统设计(论文+源代 ...

  5. LV与ASP通讯原理

    ★LV与ASP通讯原理 →经过前两节的学习,我们已经熟悉了LV类的使用,以及ASP的基本格式和输入输出了.现在我们就来看看这两样东西是怎么融合到一起的.还记得我在讲LV类的基本知识时所举的TXT那个例 ...

  6. FLASH与ASP通信入门教程(四) ASP操作数据库入门

    经过前几节的学习,我们对LV类和ASP的输入输出应该已经很熟练了吧,而且我们也已经了解了LV与ASP通讯的基本原理.这个原理可能并不复杂,不过如果你想利用它做出点东西来,关键还是要看你ASP和FLAS ...

  7. FLASH与ASP通信原理入门

    经常有人问我FLASH留言板的制作方法,无奈这东西一句两句没办法说清楚,于是就萌发了写教程的想法.可后来又一想,授人以鱼,不如授人以渔,还不如集中精力好好讲将FLASH与ASP的通讯原理,原理通了,具 ...

  8. [转]FLASH与ASP通信入门教程

    ★经常有人问我FLASH留言板的制作方法,无奈这东西一句两句没办法说清楚,于是就萌发了写教程的想法.可后来又一想,授人以鱼,不如授人以渔,还不如集中精力好好讲将FLASH与ASP的通讯原理,原理通了, ...

  9. html button 和 asp button的 各种click事件

    实验目的 探究html的button 的 onclick和onserverclick: 探究aspbutton的 OnClick和OnClientClick: 背景前言 嗯,做网页的时候button的 ...

最新文章

  1. 阿里云 centos 6.9 安装 mysql 5.7
  2. 从一个实际的例子触发,理解什么是 Rxjs 的 defer 函数
  3. CSP 1.0 语言规范
  4. Vue 学习笔记(1) Vue 基础语法 + Axios 基本使用
  5. 特斯拉限时赠送4.6万元完全自动驾驶功能,马斯克:市值能涨1000%
  6. Postman发送GET请求带中文
  7. OpenGL超级宝典(第7版)笔记9 基元装配 裁剪 光栅化
  8. 基于FairMOT的车流量统计
  9. html常用语言代码大全,常用的html代码大全
  10. 云控微信开发SDK使用教程--手机微信朋友圈图片上传服务端
  11. ppt背景图片怎么更换应用到全部
  12. 如何使用计算机管理员账户密码是什么意思,电脑管理员密码是什么
  13. navicat12No All Pattern Found!File Already Patched。
  14. 笔记本电脑外接显示器显示不全
  15. 学计算机的考研考教育学好考吗,2011年考研心路:我的两年教育学考研总结
  16. python打开word并在前台显示_Python办公自动化:自动打开word文档,你学到了吗?
  17. 【伪原创工具】最好的伪原创工具
  18. C语言实现显示每个月的天数
  19. html css 八卦图,CSS动画-八卦图
  20. 关于实现宿舍共享校园网上网的几种方法~

热门文章

  1. 简析TCP的三次握手与四次分手原理
  2. 多进程,多线程 的使用
  3. wifi天眼 一款智能远程监控软件。
  4. TP出现跳点原因总结
  5. 机器学习与R语言 多元线性回归insurance.R:保险费
  6. css禁用图片的样式显示
  7. 子女免费读公立学校--赴美访问学者福利
  8. 中M22春C、Java入门练习-7.16
  9. 转贴: 珠宝展观后记(上)
  10. matlab整数型规优化箱,matlab解决整数规划问题(蒙特卡洛法)