2

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

user957178
  • 631
  • 4
  • 15
  • 27

3 Answers3

2

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 --"
) %>
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

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?

Community
  • 1
  • 1
Justin Pihony
  • 66,056
  • 18
  • 147
  • 180
1

You could always add the option in list with the disabled option so the user cannot select it once the drop down is clicked.

MRR0GERS
  • 652
  • 5
  • 18