Question

I have been working on a project and I got stuck with a problem i.e I am able to select first and last date using asp.net calendar control but i want it to be done with calendar extender

the code shown as below is for calender control ..please provide me the solution for calendar extender with required modification..............

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();
   }
Was it helpful?

Solution

 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");


}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top