当前位置: 代码迷 >> ASP.NET >> DropDownList 默认为空的如何设置
  详细解决方案

DropDownList 默认为空的如何设置

热度:6448   发布时间:2013-02-25 00:00:00.0
DropDownList 默认为空的怎么设置?
比如
<asp:DropDownList   ID= "dropBeginYear "   runat= "server ">
<asp:ListItem   Value= "2006 "> 2006 </asp:ListItem>
<asp:ListItem   Value= "2007 "> 2007 </asp:ListItem>
<asp:ListItem   Value= "2008 "> 2008 </asp:ListItem>
<asp:ListItem   Value= "2009 "> 2009 </asp:ListItem>
<asp:ListItem   Value= "2010 "> 2010 </asp:ListItem>
</asp:DropDownList>

页面打开是默认就选中了2006  
问题是我不希望打开时dropdownlist里有值,空着就行
该如何处理
大家帮忙,谢谢!!

------解决方案--------------------------------------------------------
DropDownList1.Items.Add(new ListItem( " ", " "));
------解决方案--------------------------------------------------------
建一个item,text= "请选择 " Value= " "
验证这个不能为空,试试
------解决方案--------------------------------------------------------
孟老大写的是正确的
或者你在 <asp:ListItem Value= "2006 "> 2006 </asp:ListItem> 加一句 <asp:ListItem Value= " "> </asp:ListItem> 不就行了?
------解决方案--------------------------------------------------------
DropDownList1.Items.Add(new ListItem( " ", " "));

绑定完之后这样写就行了.
------解决方案--------------------------------------------------------
DropDownList1.Items.Add(new ListItem( " ", " "));

------解决方案--------------------------------------------------------
DropDownList1.Items.Add(new ListItem( " ", "value "));

value最好加个值
  相关解决方案