要求:在页面中有两个文本框,分别输入两个数,然后给用户提供加减乘除四种运算选项。并能根据用户的选择,在页面中相应运算结果信息。得用到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>
问题解决的话,请点下采纳
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥170 如图所示配置eNSP
- ¥20 docker里部署springboot项目,访问不到扬声器
- ¥15 netty整合springboot之后自动重连失效
- ¥15 悬赏!微信开发者工具报错,求帮改
- ¥20 wireshark抓不到vlan
- ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
- ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
- ¥15 stata安慰剂检验作图但是真实值不出现在图上
- ¥15 c程序不知道为什么得不到结果
- ¥15 键盘指令混乱情况下的启动盘系统重装