有人知道我在哪里可以找到 html 帮助器或将生成由 3 个下拉列表组成的日期选择器的东西吗?
这是我的小帮手。
我相信,这本身就是解释性的。可以调整以安排下拉列表的顺序(月/日/年或日/月/年),如果您使用的是 .NET 4,则可以为名称添加默认参数。
Edit:清除文字以减少眼睛出血
/// <summary>
/// Creates a days, months, years drop down list using an HTML select control.
/// The parameters represent the value of the "name" attribute on the select control.
/// </summary>
/// <param name="dayName">"Name" attribute of the day drop down list.</param>
/// <param name="monthName">"Name" attribute of the month drop down list.</param>
/// <param name="yearName">"Name" attribute of the year drop down list.</param>
/// <returns></returns>
public static string DatePickerDropDowns(this HtmlHelper html, string dayName, string monthName, string yearName)
{
TagBuilder daysList = new TagBuilder("select");
TagBuilder monthsList = new TagBuilder("select");
TagBuilder yearsList = new TagBuilder("select");
daysList.Attributes.Add("name", dayName);
monthsList.Attributes.Add("name", monthName);
yearsList.Attributes.Add("name", yearName);
StringBuilder days = new StringBuilder();
StringBuilder months = new StringBuilder();
StringBuilder years = new StringBuilder();
int beginYear = DateTime.UtcNow.Year - 100;
int endYear = DateTime.UtcNow.Year;
for (int i = 1; i <= 31; i++)
days.AppendFormat("<option value='{0}'>{0}</option>", i);
for (int i = 1; i <= 12; i++)
months.AppendFormat("<option value='{0}'>{0}</option>", i);
for (int i = beginYear; i <= endYear; i++)
years.AppendFormat("<option value='{0}'>{0}</option>", i);
daysList.InnerHtml = days.ToString();
monthsList.InnerHtml = months.ToString();
yearsList.InnerHtml = years.ToString();
return string.Concat(daysList.ToString(), monthsList.ToString(), yearsList.ToString());
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)