编程的问题。
publicpartialclass_Default:System.Web.UI.Page{publicclasscar{privatestringcolor;priva...
public partial class _Default : System.Web.UI.Page
{
public class car
{
private string color;
private int chelun;
public string Color
{
get
{
return color;
}
set
{
color = value;
}
}
public int Chelun
{
get
{
return chelun;
}
}
public string gg(string a, string b)
{
string c = "";
switch (a)
{
case "#red":
c += "车是红色的<br>,有" + b + "个轮子";
break;
case "#green":
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.Color = DropDownList1.SelectedIndex.ToString();
string a = onecar.Color.ToString();
string b = onecar.Chelun.ToString();
string c = onecar.gg(a, b);
Response.Write(c);
}
}
救命啊,高手。
我照这个编了,选项里都是空白的,怎么回事啊? 展开
{
public class car
{
private string color;
private int chelun;
public string Color
{
get
{
return color;
}
set
{
color = value;
}
}
public int Chelun
{
get
{
return chelun;
}
}
public string gg(string a, string b)
{
string c = "";
switch (a)
{
case "#red":
c += "车是红色的<br>,有" + b + "个轮子";
break;
case "#green":
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.Color = DropDownList1.SelectedIndex.ToString();
string a = onecar.Color.ToString();
string b = onecar.Chelun.ToString();
string c = onecar.gg(a, b);
Response.Write(c);
}
}
救命啊,高手。
我照这个编了,选项里都是空白的,怎么回事啊? 展开
展开全部
onecar.Color = DropDownList1.SelectedIndex.ToString();
值获取的时候可能包含有空格,改为onecar.Color = DropDownList1.SelectedIndex.ToString().trim();
而且
switch (a)
{
case "#red":
c += "车是红色的<br>,有" + b + "个轮子";
break;
case "#green":
c += "车是绿色的<br>,有" + b + "个轮子";
break;
case "blue":
c += "车是蓝色的<br>,有" + b + "个轮子";
break;
}
这个条件判断语句不建议把条件格式设置成这样子,条件格式不统一,应改为全部加上”#“号,或者全部不要”#“号。
值获取的时候可能包含有空格,改为onecar.Color = DropDownList1.SelectedIndex.ToString().trim();
而且
switch (a)
{
case "#red":
c += "车是红色的<br>,有" + b + "个轮子";
break;
case "#green":
c += "车是绿色的<br>,有" + b + "个轮子";
break;
case "blue":
c += "车是蓝色的<br>,有" + b + "个轮子";
break;
}
这个条件判断语句不建议把条件格式设置成这样子,条件格式不统一,应改为全部加上”#“号,或者全部不要”#“号。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.Items.Add(new ListItem("请选择你车子的颜色", "0"));
DropDownList1.Items.Add(new ListItem("红色", "#red"));
DropDownList1.Items.Add(new ListItem("绿色", "#green"));
DropDownList1.Items.Add(new ListItem("蓝色", "blue"));
}
}
public class car
{
private string color;
private int chelun;
public string Color
{
get
{
return color;
}
set
{
color = value;
}
}
public int Chelun
{
get
{
return chelun;
}
}
public string gg(string a, string b)
{
string c = "";
switch (a)
{
case "#red":
c += "车是红色的<br>,有" + b + "个轮子";
break;
case "#green":
c += "车是绿色的<br>,有" + b + "个轮子";
break;
case "blue":
c += "车是蓝色的<br>,有" + b + "个轮子";
break;
}
return c;
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
car onecar = new car();
onecar.Color = DropDownList1.SelectedValue.ToString();
string a = onecar.Color.ToString();
string b = onecar.Chelun.ToString(); //没有过值
string c = onecar.gg(a, b);
Response.Write(c);
}
{
if (!IsPostBack)
{
DropDownList1.Items.Add(new ListItem("请选择你车子的颜色", "0"));
DropDownList1.Items.Add(new ListItem("红色", "#red"));
DropDownList1.Items.Add(new ListItem("绿色", "#green"));
DropDownList1.Items.Add(new ListItem("蓝色", "blue"));
}
}
public class car
{
private string color;
private int chelun;
public string Color
{
get
{
return color;
}
set
{
color = value;
}
}
public int Chelun
{
get
{
return chelun;
}
}
public string gg(string a, string b)
{
string c = "";
switch (a)
{
case "#red":
c += "车是红色的<br>,有" + b + "个轮子";
break;
case "#green":
c += "车是绿色的<br>,有" + b + "个轮子";
break;
case "blue":
c += "车是蓝色的<br>,有" + b + "个轮子";
break;
}
return c;
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
car onecar = new car();
onecar.Color = DropDownList1.SelectedValue.ToString();
string a = onecar.Color.ToString();
string b = onecar.Chelun.ToString(); //没有过值
string c = onecar.gg(a, b);
Response.Write(c);
}
来自:求助得到的回答
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
事件不是这个事件。你写在Mousedwon事件里看看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询