如果下拉列表没有选定的值,有没有办法包含默认的空选项(或带有文本)?
发布于 2009-02-03 04:39:52
下面将把string.Empty添加到在ViewData“菜单”项目中指定的SelectList (或IEnumerable)前面。select将具有id和名称MenuID
。
<%= Html.DropDownList( "MenuID",
(IEnumerable<SelectListItem>)ViewData["Menu"],
string.Empty ) %>
发布于 2013-02-02 05:39:26
这里给出的解决方案对我来说非常有效:http://forums.asp.net/t/1142484.aspx/1
基本思想是您将DropDownList
的AppendDataBoundItems
属性设置为true
,然后在DropDownList
中放置一个asp:ListItem
,它将成为您的默认项,所有数据绑定项都在它后面。
https://stackoverflow.com/questions/506001
复制相似问题