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

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

1个回答

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>

图片说明

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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问