Guest User

Untitled

a guest
May 16th, 2012
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. Creating a dropdownlist c# mvc3
  2. <% List<string> foo = new List<string>();
  3. foo.Add("Showing");
  4. foo.Add("ComingSoon);"
  5. foo.Add("Out");
  6.  
  7. Html.DropDownList(foo, Model.Status); %>
  8.  
  9. Html.DropDownList("Status",
  10. new SelectListItem[]{ new SelectListItem{ Text= "Showing", Value="Showing"},
  11. //same for others
  12. });
  13.  
  14. <%: Html.DropDownListFor(model=> model.Status,
  15. new List<SelectListItem>() {
  16. new SelectListItem{ Text= "Showing", Value="Showing"},
  17. new SelectListItem{ Text= "ComingSoon", Value="ComingSoon"},
  18. new SelectListItem{ Text= "Out", Value="Out"}
  19. }); %>
  20.  
  21. @{
  22. List<KeyValuePair<int, string>> dropdownList =
  23. new List<KeyValuePair<int, string>>();
  24. dropdownList.Add(new KeyValuePair<int, string>(0,"Showing"));
  25. dropdownList.Add(new KeyValuePair<int, string>(1,"ComingSoon"));
  26. dropdownList.Add(new KeyValuePair<int, string>(2,"Out"));
  27. SelectList selectList = new SelectList(dropdownList, "key", "value", 0);
  28.  
  29. }
  30.  
  31. @Html.DropDownList("foo", selectList)
Advertisement
Add Comment
Please, Sign In to add comment