DropDownList控件怎么起作用?
我用vs2005在设计里边,加了一个DropDownList控件,属性值在哪儿能实现?我填了3个颜色源代码:usingSystem;usingSystem.Data;us...
我用vs2005在设计里边,加了一个DropDownList控件,属性值在哪儿能实现?我填了3个颜色源代码:
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;
public partial class _Default : System.Web.UI.Page
{
public class car
{
private string color;
private int chelun = 4;
public string Color
{
get
{
return color;
}
set
{
color = value;
}
}
public int Chelun
{
get
{
return chelun;
}
}
public string getinfo(string a, string b)
{
string c = "";
switch (a)
{ case "#red":
c += "这部车是红色的<br>,有" + b + "个轮子!";
break;
case "#black":
c += "这部车是黑色的<br>,有" + b + "个轮子!";
break;
case "#green":
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.ToString();
string a = onecar.Color.ToString();
string b = onecar.Chelun.ToString();
string c = onecar.getinfo(a, b);
Response.Write(c);
}
}
可是调试并没有起作用?其高手指点一下!谢谢啦! 展开
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;
public partial class _Default : System.Web.UI.Page
{
public class car
{
private string color;
private int chelun = 4;
public string Color
{
get
{
return color;
}
set
{
color = value;
}
}
public int Chelun
{
get
{
return chelun;
}
}
public string getinfo(string a, string b)
{
string c = "";
switch (a)
{ case "#red":
c += "这部车是红色的<br>,有" + b + "个轮子!";
break;
case "#black":
c += "这部车是黑色的<br>,有" + b + "个轮子!";
break;
case "#green":
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.ToString();
string a = onecar.Color.ToString();
string b = onecar.Chelun.ToString();
string c = onecar.getinfo(a, b);
Response.Write(c);
}
}
可是调试并没有起作用?其高手指点一下!谢谢啦! 展开
2个回答
展开全部
onecar.Color = DropDownList1.ToString();
有问题 调用DropDownList的值没这么写的 这么写啥也调不到
DropDownList有3种取值
DropDownList1.SelectedItem.ToString()
DropDownList1.SelectedValue.ToString()
DropDownList1.SelectedIndex.ToString()
第一种是取你添加DropDownList的text项的值
第二种是取你添加DropDownList的value项的值
第三种是取当前选项的索引值
举例:
ListItem item = new ListItem();
item.Value = "100";
item.Text = "aaa";
item.Value = "101";
item.Text = "bbb";
DropDownList2.Items.Add(item);
显示为aaa bbb 如选bbb则
DropDownList1.SelectedItem.ToString()为bbb
DropDownList1.SelectedValue.ToString()为101
DropDownList1.SelectedIndex.ToString()为1
有问题 调用DropDownList的值没这么写的 这么写啥也调不到
DropDownList有3种取值
DropDownList1.SelectedItem.ToString()
DropDownList1.SelectedValue.ToString()
DropDownList1.SelectedIndex.ToString()
第一种是取你添加DropDownList的text项的值
第二种是取你添加DropDownList的value项的值
第三种是取当前选项的索引值
举例:
ListItem item = new ListItem();
item.Value = "100";
item.Text = "aaa";
item.Value = "101";
item.Text = "bbb";
DropDownList2.Items.Add(item);
显示为aaa bbb 如选bbb则
DropDownList1.SelectedItem.ToString()为bbb
DropDownList1.SelectedValue.ToString()为101
DropDownList1.SelectedIndex.ToString()为1
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询