嗨,我是 C# 新手,我正在尝试实现与该网站相关的示例:http: //www.devmanuals.com/tutorials/ms/aspdotnet/dropdownlist.html
我要做的是创建 Web 部件并将其部署到共享点:代码:
<%@ Page Title="" Language="C#" MasterPageFile="~/RoseindiaMaster.master"
AutoEventWireup="true" CodeFile="DropDownList.aspx.cs" Inherits="DropDownList" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.style3
{
color: #800000;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div>
<h2 style="color:Green">DropDownList in ASP.NET 4 , C#</h2>
<strong><span class="style3">Enter first number:</span>
</strong>
<br />
<asp:TextBox ID="txt1" runat="server" Text="12"/>
<br />
<br />
<span class="style3">
<strong>Enter second number:
</strong>
</span>
逻辑代码:
protected void drp1_SelectedIndexChanged(object sender, EventArgs e)
{
double firstno = Convert.ToDouble(txt1.Text);
double secondno = Convert.ToDouble(txt2.Text);
if(drp1.SelectedIndex == 1)
{
double add = firstno + secondno;
label1.Text = "Addition is :" + add;
}
我不断收到错误:无法识别 txt1,请告知,我是 C# 新手