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:
<%= 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? 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. I will double check...
UPDATE It looks like there is nothing like placeholder
(HTML5 input option) for select. However, it looks like the best you have has already been answered here: How do I make a placeholder for a 'select' box?
您始终可以在列表中添加带有禁用选项的选项,这样,一旦单击下拉列表,用户就无法选择它。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.