在下拉列表中,第一个月应从4月开始,到3月结束。 如果当前月份为5月,则应仅显示4月,同样,如果当前月份为3月,则应动态列出(4月至2月)。
如果当前月份为4月,则不应显示任何内容。
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();
上面是我正在运行的代码,但显示的时间是从jan到dec。
答案 0 :(得分:0)
类似这样的东西:
select users0_.group_id as group_id1_0_0_, users0_.user_id as user_id2_0_0_, user1_.id as id1_7_1_
from group_users users0_
inner join User user1_ on users0_.user_id=user1_.id
where users0_.group_id=?
答案 1 :(得分:0)
这有效(我认为):
const int startMonth = 4;
var previousMonth = ((DateTime.Now.Month - 2) % 12) + 1;
var months = Enumerable.Range(startMonth - 1, (previousMonth - startMonth + 13) % 12).Select(i => new
{
I = (i % 12) + 1, M = DateTimeFormatInfo.CurrentInfo.GetMonthName((i % 12) + 1)
});
DropDownList3.DataSource = months;
DropDownList3.DataTextField = "M";
DropDownList3.DataValueField = "I";
DropDownList3.DataBind();