在日历扩展程序中添加天数

时间:2013-07-08 11:15:44

标签: asp.net c#-4.0 calendarextender

我一直在研究一个项目而且我遇到了一个问题,即我能够使用asp.net日历控件选择第一个和最后一个日期,但我希望它能用日历扩展器完成

下面显示的代码用于日历控制..请为日历扩展器提供所需修改的解决方案..............

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
   {
    Calendar1.SelectionMode = CalendarSelectionMode.DayWeek;
    //ArrayList selectedDates = new ArrayList();
    string s = Calendar1.SelectedDate.ToShortDateString();
    DateTime today = DateTime.Parse(s);
    DateTime firstDay = today.AddDays(-(double)(today.DayOfWeek));
    DateTime lastDay = today.AddDays(6 - (double)(today.DayOfWeek));
    for (int loop = 0; loop < 7; loop++)
        Calendar1.SelectedDates.Add(firstDay.AddDays(loop));
    lblStartOfWeek.Text = firstDay.ToLongDateString();
    lblEndOfWeek.Text = lastDay.ToLongDateString();
    lblStartOfWeek.Visible = true;
    lblEndOfWeek.Visible = true;
    checkLessonPlan();
   }

1 个答案:

答案 0 :(得分:0)

 protected void Calendar1_ontextchanged(object sender, EventArgs e)
{

    string numberofdays=   Convert.ToDateTime(this.TextBox1.Text).DayOfWeek.ToString("d");
    DateTime select = Convert.ToDateTime(TextBox1.Text);
    lblStartOfWeek.Text = select.AddDays(-Convert.ToInt32(numberofdays)).ToString("dd MMMM yyyy");
    lblEndOfWeek.Text = select.AddDays(6-Convert.ToInt32(numberofdays)).ToString("dd MMMM yyyy");


}