我在屏幕上显示日历。日历会突出显示“日记条目”列表中存储的日期。 ATM用户可以使用日历顶部的箭头浏览任何一年中的任何月份。我只希望用户能够在存储日期的月份之间导航,例如,如果日期是btn 1/3/2013& 4/7/2013用户无法将日历移动到5/8/2013,如何在日期到达时禁用箭头键?
<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;
}
答案 0 :(得分:0)
我认为(轻松)禁用箭头是不可能的,最简单的方法是使用DayRender
事件来设置IsSelectable
property。
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;
// adjust accordingly
if (e.Day.Date < MinDate || e.Day.Date > MaxDate)
{
e.Day.IsSelectable = false;
e.Cell.BackColor = Color.LightGray;
}
}