日期:2014-05-19  浏览次数:20476 次

DropDownList如何添加一个“-请选择-”选项啊!????
DropDownList.DataSource=dsroles;
DropDownList.DataValueField= "id ";
DropDownList.DataTextField= "RName ";
DropDownList.DataBind();
上面是从数据库中读取数据然后绑定到DropDownList
下面是追加一个“请选择”,可是不知道为什么就是不显示,求大哥们给点意见!!
帮小弟解决这个问题!
ListItem   list=new   ListItem( "-请选择- ", "-1 ");
DropDownList.Items.Add(list);
DropDownList.SelectedIndex=ddlName.Items.Count-1;


------解决方案--------------------
在后面再加一句
DropDownList.DataBind();
------解决方案--------------------
定义一个listitem
DropDownList.Items.insertat(xx,0)
------解决方案--------------------
try

DropDownList.DataBind();后面加
DropDownList.Items.Insert(0, "-请选择- ");

------解决方案--------------------
回答完毕就接分
------解决方案--------------------
ListItem list=new ListItem( "-请选择- ", "-1 ");
DropDownList.Items.Add(list);
list.selected=true;