注册 登录
编程论坛 ASP技术论坛

我是菜鸟,请各位前辈看一下问题在那里?

kaikai2008 发布于 2010-06-01 13:20, 347 次点击
public partial class wecomle : System.Web.UI.Page
{
       public class car {
        private string colors;
      private int chel=4;
        public string Colors
        {
           
            set
            {
                colors = value;            
            }
            get
            {
                return colors;
            }
        }
        public int Chel
        {
            get
            {
                return chel;
            }
        }
        public string getinfo(string a, string b)
        {
            string c="  ";
            switch (a)
            {
                case "#red":
                    c += "你小车的颜色是红色<br>共有" + b + "个!";
                    break;
                case "#black":
                    c += "你小车的颜色是黑色<br>共有" + b + "个!";
                    break;
                case "#blue":
                    c += "你小车的颜色是蓝色<br>共有" + b + "个!";
                    break;
            }
            return c;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        car onecar = new car();
        onecar.Colors = DropDownList1.SelectedValue.ToString();
        string a = onecar.Colors.ToString();
        string b = onecar.Chel.ToString();
        string c = onecar.getinfo(a,b);
        Response.Write(c);

    }
    protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
    {

    }
}
选择颜色,没有显东西!好像swith块没有用?
1 回复
#2
yms1232010-06-01 19:05
public partial class wecomle : System.Web.UI.Page
{
       public class car
       {
          private string colors;
          private int chel=4;
          public string Colors
          {
           
            set
            {
                colors = value;            
            }
            get
            {
                return colors;
            }
         }
         public int Chel
         {
            get
            {
                return chel;
            }
         }
         public string getinfo(string a, string b)
         {
            string c="  ";
            switch (a)
            {
                case "#red":
                    c += "你小车的颜色是红色<br>共有" + b + "个!";
                    break;
                case "#black":
                    c += "你小车的颜色是黑色<br>共有" + b + "个!";
                    break;
                case "#blue":
                    c += "你小车的颜色是蓝色<br>共有" + b + "个!";
                    break;
             }
            return c;
         }
     }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        car onecar = new car();
        onecar.Colors = DropDownList1.SelectedValue.ToString();
        string a = onecar.Colors.ToString();
        string b = onecar.Chel.ToString();
        string c = onecar.getinfo(a,b);
        Response.Write(c);

    }
    protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
    {

    }
}
看样子你这个创建的是内部类
1