.net日历控件 Calendar选择多个日期

来源:http://dev.mjxy.cn/a-Calendar-calendar-control-multiple-dates-selection.aspx

稍微修改了一下:


 public List<DateTime> SelectDate
        {
            set
            {
                ViewState["sd"] = value;
            }
            get
            {
                if (ViewState["sd"] == null)
                    ViewState["sd"] = new List<DateTime>();
                return (List<DateTime>)ViewState["sd"];
            }
        }
        protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
        {
            List<DateTime> selectDate = SelectDate;
            foreach (var item in SelectDate)
            {
                if (e.Day.IsOtherMonth)
                    e.Cell.Controls.Clear();
                if (e.Day.Date == item)
                    e.Cell.BackColor = System.Drawing.Color.Red;
            }
        }
        protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {

            List<DateTime> lst = SelectDate;
            if (lst.Contains(Calendar1.SelectedDate))
            {
                lst.Remove(Calendar1.SelectedDate);
            }
            else
            {
                lst.Add(Calendar1.SelectedDate);
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            foreach (var item in SelectDate)
            {
                Response.Write(item.ToString() + "<BR/>");
            }          
        }   

你可能感兴趣的:(.net日历控件 Calendar选择多个日期)