简体   繁体   English

我如何为下拉列表框添加“请选择...”选项

[英]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.

相关问题 如何使用javascript将选项添加到html表单下拉列表中 - how do I add an option to a html form dropdown list with javascript 如果选择了另一个选择下拉列表中的一个选项,如何显示选择下拉列表 - How do I display a select dropdown list when one option on another select dropdown is selected 如何添加一个下拉菜单,当您 select 一个选项并单击发送时,它会显示 email 中的选项? - How do I add a dropdown menu that when you select an option and click send it shows the option in the email? 如何将“ selected =&#39;selected&#39;”属性分配给特定 <option>在一个<select>清单。请只使用VanillaJS - How do I assign a “ selected='selected' ” attribute to a specific <option> in a <select> list. VanillaJS only please 如何制作选择框的下拉选项 - How to make the dropdown option of a select box 如何使用jquery在父窗口的选择框中添加选项? - How do I add an option to a select box in a parent window using jquery? 在 react-select 选项下拉菜单中需要一个输入框 - Need an Input box inside react-select option dropdown Ruby on Rails Form 添加带有文本框的“其他”选项到 Select 下拉列表 - Ruby on Rails Form Add an "Other" Option with Text Box to Select Dropdown 如何使用jQuery在选择框选项中获取类的值 - how do I get the value of a class in the select box option with jquery 如何在下拉选择选项中添加文本框 - how to add textbox in dropdown select option
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM