当前位置: 代码迷 >> ASP.NET >> 赋值给DropDownList的Text,赋不上,该怎么处理
  详细解决方案

赋值给DropDownList的Text,赋不上,该怎么处理

热度:1224   发布时间:2013-02-25 00:00:00.0
赋值给DropDownList的Text,赋不上
通过一个对象获取要赋予的值:
FieldValue model = fvbll.GetModel(int.Parse(id), int.Parse(lblId.Text));

将获取的值赋给DropDownListList:
DropDownList ddl = item.FindControl("DropDownListType") as DropDownList;
ddl.Text = model.Content;

若ddl.Text的初始值都是"0";当model.Content="wangjingru"是ddl.Text获取的值时"wangjingru"
但是当model.Content="wang jingru"是ddl.Text获取的值时"0"

只要获取的值里面有空格的都获取不了值,这是怎么回事呀??

------解决方案--------------------------------------------------------
这个不能直接.Text赋值吧。。。
最起码
DropDownList1.Items.Insert(0, new ListItem("Text", "Value"));
------解决方案--------------------------------------------------------
用ddl.Items.Insert试试
ddl.Items.Insert(i, new ListItem("MyName”,“MyValue”));//i表示你要插入的位置
------解决方案--------------------------------------------------------
DropDownList 只能添加 DropDownList .Items.Insert 不能赋值
莫非你所说的复制 是想DropDownList的项定位在你给的那个值上面?
------解决方案--------------------------------------------------------
樓上都正解
  相关解决方案