文本框 下拉列表框 按钮 标签 控件的简单运用 计算器实例

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





    无标题页


    
+ - * /  

using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class caculate : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { int a = int.Parse(this.TextBox1.Text);//获取第一个文本框的输入值并转为整形 int b = int.Parse(this.TextBox2.Text);//获取第二个文本框的输入值并转为整形 switch (this.DropDownList1.SelectedValue) { //以下拉列表的选择符号为判断依据 case "+": this.Label1.Text = (a + b).ToString();//运算后转为字符串赋值给标签控件文本显示 break; case "-": this.Label1.Text = (a - b).ToString(); break; case "*": this.Label1.Text = (a * b).ToString(); break; case "/": this.Label1.Text = (a / b).ToString(); break; } } }

 

你可能感兴趣的:(asp.net)