读书人

请教asp.net(c#)的DropDownList是怎样

发布时间: 2012-02-02 23:57:14 作者: rapoo

请问asp.net(c#)的DropDownList是怎样用的?(绑定了SQL)
例如:
我在SQL中建了表

表test:
列lum 有值 A,B,C

我用一个DropDownList 绑定了。test的lum,自然我在页面显示的下拉就是A,B,C了~

我想选中某个选项就改变一些控件属性,如:一个lable,把lable的text改为hello world;

我是这样做的:
if (DropDownList1.DataValueField == "A")
{
Label5.Text = "hello world";
}
-----------------------------------------------

if (DropDownList1.DataValueField== "A")
{
Label5.Text = "hello world";
}
------------------------------------------------
if (DropDownList1.SelectedValue== "A")
{
Label5.Text = "hello world";
}
--------------------------------------------------

3个都不行吖!~ —ropDownList1在绑定的时候是钩上刷新功能的)

哭死我了!~ 应该怎样做吖?是不是要把A转为string?还是怎样?
求救!~




[解决办法]
你是肯定是用 ListItem 型 和"A" 比多 2不是同一型
如果你定候 A 是定在 DataTextField 上就用比
if (DropDownList1.SelectedItem.Text== "A")

读书人网 >asp.net

热点推荐