这个事Default.aspx的代码:<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="Ch2WebForm" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="Form1" method="post" runat="server">
    <p style="FONT-WEIGHT:bold;FONT-SIZE:12pt;COLOR:Maroon;
              font-FAMILY:none;text-align:center">
            This is my first ASP.NET form<br />
        <br />
        </p>
        Select a color from the followint list,and then click the Button<br />
        <p>&nbsp
        &nbsp; &nbsp;
        <asp:DropDownList ID="ddlColorList" runat="server" Width="88px">
        </asp:DropDownList>
        &nbsp; &nbsp;&nbsp;
        <asp:Button ID="btnSelectColor" runat="server" Text="apply color"></asp:Button>
        &nbsp;&nbsp;
        </p>
        <p>
        &nbsp; &nbsp;
        <asp:Label ID="lblSelectedColor" runat="server" Height="16px" Text="Label" Width="72px" AssociatedControlID="ddlColorList"></asp:Label>
        </p>
    </form>
</body>
</html>这个是Default.aspx.cs的代码:using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections; 
public partial class Ch2WebForm : System.Web.UI.Page 
{
    protected void Page_Load(object sender, System.EventArgs e)
    {
        if (!(Page.IsPostBack))
        {
            ArrayList colors = new ArrayList(3);
            colors.Add("Red");
            colors.Add("green");
            colors.Add("Blue");
            ddlColorList.DataSource = colors;
            ddlColorList.DataBind();
        }
    
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        lblSelectedColor.Text = "You selected" +
                                              ddlColorList.SelectedItem.Text;
        lblSelectedColor.ForeColor =
            System.Drawing.Color.FromName(ddlColorList.SelectedItem.Text);
    }
}
程序显示如下结果:应该显示的效果是这样的:下图
请问是哪儿错了???

解决方案 »

  1.   

    是不是大小写问题 green 应该Green
      

  2.   

    <asp:DropDownList ID="ddlColorList" runat="server" Width="88px" AutoPostback="true">
            </asp:DropDownList> 
      

  3.   

    楼上的,跟AutoPost没关系,他用的是Button的单击事件,我同意1楼的观点,很可能是大小写的问题
      

  4.   

    我试了没问题,你看看ddlColorList.SelectedItem.Text; 在按钮点击后是green吗
      

  5.   

    <asp:Button ID="btnSelectColor" runat="server" Text="apply color" onClick="Button1_Click">
    少了事件