当前位置: 代码迷 >> ASP.NET >> 怎么在DropDownList中添加新项并设置显示值和value值
  详细解决方案

怎么在DropDownList中添加新项并设置显示值和value值

热度:2813   发布时间:2013-02-25 00:00:00.0
如何在DropDownList中添加新项并设置显示值和value值
显示值和value值是不同的

------解决方案--------------------------------------------------------
ListItem li = new ListItem();
li.Text = "壹点壹 ";
li.Value = "onedotone ";
DropDownList1.Item.Add(li);

------解决方案--------------------------------------------------------
MyDropDownList.Items.Add(new ListItem( "myText ", "myValue "));
------解决方案--------------------------------------------------------
设置显示的项MyDropDownList.Items.FindByValue( "值 ").Selected=true
------解决方案--------------------------------------------------------
DropDownList1.Items.Insert(0, new ListItem(text, value));
0 为插入的INDEX
TEXT 为显示值
VALUE 为VALUE值
  相关解决方案