日期:2014-05-18  浏览次数:20512 次

请问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个都不行吖!~ (DropDownList1在绑定的时候是钩上刷新功能的)

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




------解决方案--------------------
你是肯定是用 ListItem 類型 和"A" 比較多 2個不是同一個類型
如果你綁定時候 A 是綁定在 DataTextField 上就用這樣比較
if (DropDownList1.SelectedItem.Text== "A")