| Line | |
|---|
| 1 | using System;
|
|---|
| 2 | using System.Globalization;
|
|---|
| 3 | using System.Text;
|
|---|
| 4 | using System.Web.Mvc;
|
|---|
| 5 |
|
|---|
| 6 | namespace 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.