NumberRangeDropdownListExtensions.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Bowin.Web.Controls.Mvc;
  7. namespace EMIS.Web.Controls
  8. {
  9. public static class NumberRangeDropdownListExtensions
  10. {
  11. public static MvcHtmlString NumberRangeDropdownList(this HtmlHelper htmlHelper,
  12. int minValue, int maxValue,
  13. DropdownListOptions dropdownListOptions = null,
  14. System.Collections.Generic.IDictionary<string, string> htmlAttributes = null)
  15. {
  16. if (dropdownListOptions == null)
  17. dropdownListOptions = new DropdownListOptions();
  18. List<int> valueList = new List<int>();
  19. for (int i = minValue; i <= maxValue; i ++)
  20. {
  21. valueList.Add(i);
  22. }
  23. dropdownListOptions.ItemList = valueList.Select(x => new DropdownListItem { Text = x.ToString(), Value = x.ToString() }).ToList();
  24. if (dropdownListOptions.SelectedValue == null)
  25. {
  26. dropdownListOptions.SelectedValue = DropdownList.PLEASE_SELECT.ToString();
  27. }
  28. return htmlHelper.DropdownList(dropdownListOptions, htmlAttributes);
  29. }
  30. }
  31. }