root/trunk/Wierszowki/Wierszowki.Web/Helpers/SelectExtension.cs @ 966

Wersja 842, 1.3 KB (wprowadzona przez alina, 17 years temu)

fix #207, #193, #205

Line 
1using System;
2using System.Globalization;
3using System.Text;
4using System.Web.Mvc;
5
6namespace Wierszowki.Helpers
7{
8    public static class SelectExtension
9    {
10        public static string MonthSelect(this HtmlHelper helper, string id)
11        {
12            var sb = new StringBuilder();
13            sb.AppendFormat("<select id=\"{0}\" name=\"{0}\">", id);
14            for (var i = 1; i <= 12; i++)
15            {
16                sb.AppendFormat("<option value=\"{0}\"{2}>{1}</option>", i, new CultureInfo("pl-PL").DateTimeFormat.GetMonthName(i),
17                                DateTime.Now.Month == i ? " selected=\"selected\"" : "");
18            }
19            sb.Append("</select>");
20           
21            return sb.ToString();
22        }
23
24        public static string YearSelect(this HtmlHelper helper, string id)
25        {
26            var sb = new StringBuilder();
27            sb.AppendFormat("<select id=\"{0}\" name=\"{0}\">", id);
28            sb.AppendFormat("<option value=\"{0}\">{0}</option>", DateTime.Now.AddYears(-1).Year);
29            sb.AppendFormat("<option value=\"{0}\" selected=\"selected\">{0}</option>", DateTime.Now.Year);
30            sb.AppendFormat("<option value=\"{0}\">{0}</option>", DateTime.Now.AddYears(1).Year);
31            sb.Append("</select>");
32
33            return sb.ToString();
34        }
35       
36    }
37}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.