【发布时间】:2019-02-26 14:10:15
【问题描述】:
在下拉列表中,第 1 个月应从 4 月开始,到 3 月结束。 如果当前月份是 5 月,它应该只显示 4 月,同样,如果当前月份是 3 月,它应该动态列出(4 月到 2 月)。
如果当前月份是四月,则不应显示任何内容。
var previousMonth = DateTime.Now.Month == 1 ? 1 : DateTime.Now.Month - 1 ;
var months = Enumerable.Range(1, previousMonth).Select(i => new { I = i, M =
DateTimeFormatInfo.CurrentInfo.GetMonthName(i) });
DropDownList3.DataSource = months;
DropDownList3.DataTextField = "M";
DropDownList3.DataValueField = "I";
DropDownList3.DataBind();
上面是我的代码,它正在工作,但它从一月到十二月显示。
【问题讨论】:
-
请在minimal reproducible example 上发布您为解决此问题所做的尝试。
-
你是新的贡献者,请发布你的代码和什么不起作用。
-
@Gauravsa 我已经编辑了我的问题,请检查代码。
-
@CoolBots 我已经用代码更新了问题,请检查