![]() |
#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) { } } 看样子你这个创建的是内部类 |
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块没有用?