【发布时间】:2013-12-11 16:25:25
【问题描述】:
如何在asp.net的日历控件中以编程方式选择和取消选择多个日期?
using System.Collections.Generic;
public static List<DateTime> list = new List<DateTime>();
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.IsSelected == true)
{
list.Add(e.Day.Date);
}
Session["SelectedDates"] = list;
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
if (Session["SelectedDates"] != null)
{
List<DateTime> newList = (List<DateTime>)Session["SelectedDates"];
foreach (DateTime dt in newList)
{
Calendar1.SelectedDates.Add(dt);
}
list.Clear();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Session["SelectedDates"] != null)
{
List<DateTime> newList = (List<DateTime>)Session["SelectedDates"];
foreach (DateTime dt in newList)
{
Response.Write(dt.ToShortDateString() + "<BR/>");
}
}
}
上面的代码只选择了多个日期,如何在上面的代码中一一取消选择日期?
【问题讨论】: