我在屏幕上显示日历。日历突出显示存储在“日记条目”列表中的日期。ATM 用户可以使用日历顶部的箭头浏览任何一年中的任何一个月。我只希望用户能够在存储日期的月份之间导航,例如,如果日期是 btn 2013 年 1 月 3 日和 2013 年 4 月 7 日,则用户无法将日历移动到 2013 年 5 月 8 日,如何到达日期时可以禁用箭头键吗?
<asp:Calendar ID="calendarToDisplayWorkSiteDates" VerticalAlign="top" HorizontalAlign="left" runat="server" OnSelectionChanged="LoadRequestedDate_OnClick" OnDayRender="cal_DayRender"></asp:Calendar>
public void BindData()
{
DateTime Date = new DateTime(DiaryDate.Year, DiaryDate.Month, 1);
DateTime startOfMonth = Date.AddMonths(-2);
DateTime endOfMonth = startOfMonth.AddMonths(5).AddDays(-1);
int siteId = this.siteId;
ClarkeDBDataContext db = new ClarkeDBDataContext();
List<Diary_Entry> DiaryEntry = new List<Diary_Entry>();
DiaryEntry = (from DE in db.Diary_Entries
where DE.Site_Id == siteId
&& DE.Date >= startOfMonth && DE.Date <= endOfMonth
orderby DE.Date ascending
select DE).ToList();
if (DiaryEntry != null)
{
FirstDateLabel.Text = DiaryEntry.FirstOrDefault().Date.Date.ToShortDateString();
SecondDateLabel.Text = DiaryEntry.LastOrDefault().Date.Date.ToShortDateString();
foreach (DateTime d in DiaryEntry.Select(de => de.Date))
{
calendarToDisplayWorkSiteDates.SelectedDates.Add(d);
}
}
else
{
FirstDateLabel.Text = "None";
SecondDateLabel.Text = "None";
}
}
protected void cal_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.IsToday)
e.Cell.BackColor = Color.Red;
else if (e.Day.Date == this.DiaryDate)
e.Cell.BackColor = Color.Green;
else if (e.Day.IsSelected)
e.Cell.BackColor = Color.Blue;
}