要求:在页面中有两个文本框,分别输入两个数,然后给用户提供加减乘除四种运算选项。并能根据用户的选择,在页面中相应运算结果信息。得用到button,textbox等控件!!谢谢!!!
1条回答
- threenewbee 2020-05-17 09:31关注
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Q1072616 { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { if (DropDownList1.SelectedValue == "+") { Label1.Text = (double.Parse(TextBox1.Text) + double.Parse(TextBox2.Text)).ToString(); } else if (DropDownList1.SelectedValue == "-") { Label1.Text = (double.Parse(TextBox1.Text) - double.Parse(TextBox2.Text)).ToString(); } else if (DropDownList1.SelectedValue == "*") { Label1.Text = (double.Parse(TextBox1.Text) * double.Parse(TextBox2.Text)).ToString(); } else if (DropDownList1.SelectedValue == "/") { Label1.Text = (double.Parse(TextBox1.Text) / double.Parse(TextBox2.Text)).ToString(); } } } }
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Q1072616._Default" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <%-- <h2> Welcome to ASP.NET! </h2> <p> To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>. </p> <p> You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&clcid=0x409" title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>. </p>--%> <h2> 计算器 </h2> <p> 计算: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem Selected="True">+</asp:ListItem> <asp:ListItem>-</asp:ListItem> <asp:ListItem>*</asp:ListItem> <asp:ListItem>/</asp:ListItem> </asp:DropDownList> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> </p> <p> 结果: <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </p> </asp:Content>
问题解决的话,请点下采纳
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 安卓adb backup备份应用数据失败
- ¥15 eclipse运行项目时遇到的问题
- ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
- ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
- ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
- ¥50 成都蓉城足球俱乐部小程序抢票
- ¥15 yolov7训练自己的数据集
- ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
- ¥15 电力市场出清matlab yalmip kkt 双层优化问题
- ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)