[英]How do I need to add 'Please select…' option for the dropdown list box
I have this code I have to add 'please select..' in the dropdown list box. 我有此代码,我必须在下拉列表框中添加“请选择..”。
<%=Html.DropDownList("defaultSelection", new SelectList(Model.VariableDefaultSelections.ToList(), "ba_Object_id", "ba_Object_id", ViewData["DefaultSelectId"]))%>
Can any body help me out . 有谁能帮助我。
Thanks 谢谢
There's an overload of the DropDownList helper which allows you to achieve that: DropDownList帮助器的重载使您可以实现:
<%= Html.DropDownList(
"defaultSelection",
new SelectList(
Model.VariableDefaultSelections.ToList(),
"ba_Object_id",
"ba_Object_id",
ViewData["DefaultSelectId"]
),
"-- Please Select --"
) %>
You will have to add it in your SelectList, maybe with an Id of -1? 您将不得不将其添加到您的SelectList中,也许其ID为-1? The only way I know of is to add it as an option. 我知道的唯一方法是将其添加为选项。 If you are using HTML5, then I think you might be able to add a meta tag, but that might just be for input types. 如果您使用的是HTML5,那么我认为您可能可以添加一个meta标记,但这可能仅适用于输入类型。 I will double check... 我会仔细检查...
UPDATE It looks like there is nothing like placeholder
(HTML5 input option) for select. UPDATE似乎没有可供选择的placeholder
(HTML5输入选项)。 However, it looks like the best you have has already been answered here: How do I make a placeholder for a 'select' box? 但是,您似乎已经在这里得到了最好的回答: 如何为“选择”框创建占位符?
您始终可以在列表中添加带有禁用选项的选项,这样,一旦单击下拉列表,用户就无法选择它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.