weixin_46878047
weixin_46878047
2020-05-17 09:21
采纳率: 42.9%
浏览 143

急求大佬帮助!!制作一个asp.net页面!!

要求:在页面中有两个文本框,分别输入两个数,然后给用户提供加减乘除四种运算选项。并能根据用户的选择,在页面中相应运算结果信息。得用到button,textbox等控件!!谢谢!!!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • caozhy
    已采纳
    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&amp;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>
    
    

    图片说明

    问题解决的话,请点下采纳

    点赞 评论

相关推荐