0

我在屏幕上显示日历。日历突出显示存储在“日记条目”列表中的日期。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;
        }
4

1 回答 1

0

我认为不可能(轻松地)禁用箭头,最简单的方法是使用DayRender事件来设置IsSelectable属性

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;
    }
}
于 2013-04-26T14:30:13.020 回答