Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please help me to add a default value in drop down list. This is populated drop down list.
Thanks in advance. below is my single line code.

HTML
<pre>@Html.DropDownList("leaveCode", ViewBag.leaveCode as List<SelectListItem>,"Select", new { htmlAttributes = new { @class = "form-control" }, @id = "locationsel", @style = "width:150px;" })


in above line code i want to add a value called "some text" that should be display in drop down list.

What I have tried:

Please help me out .

Thanks
Posted
Updated 12-Apr-17 0:32am
v2
Comments
Sunasara Imdadhusen 12-Apr-17 5:42am    
You can add your values in ViewBag.leaveCode
Karthik_Mahalingam 12-Apr-17 5:52am    
is the default value part of the leaveCode ?

1 solution

Yes. It is default value of the leaveCode.

in viewBag
ViewBag.leaveCode = new SelectList(db.ApplyLeaveVMs, "alid", "leaveCode", applyLeaveVM.leaveCode);


above is my ViewBang

if I do like below it will through error.
ViewBag.leaveCode = new SelectList(db.ApplyLeaveVMs, "alid", "leaveCode","LOP", applyLeaveVM.leaveCode);

So, please let me know how I can add default value in ddl.
 
Share this answer
 
v2
Comments
Karthik_Mahalingam 12-Apr-17 7:21am    
is this solution or comment ?
Member 12224368 13-Apr-17 4:58am    
It is the comment sir,. Please let me know the solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900