This is a migrated thread and some comments may be shown as answers.

Recurrence Exception Doesn't Work

1 Answer 52 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Gary
Top achievements
Rank 1
Gary asked on 25 Jun 2011, 06:33 PM
Followed is my code used to test recurrence exception functionality. I could never get it to work. The grid shows the appointment occurrences correctly. Hello World recurs exactly 4 time starting from today. However the first recurrence exception doesn't work. I wonder if you guys can provide us a simple code how to create an exception for occurrences.

List<Appointment> lstAppt = new List<Appointment>();
            Appointment objAppt;
            objAppt = new Appointment();
            objAppt.Start = DateTime.Now;
            objAppt.End = DateTime.Now.AddHours(1);
            objAppt.Description = "Hello World";
            objAppt.ID = 1;
            objAppt.RecurrenceParentID = 1;
             
            RecurrenceRange objRange = new RecurrenceRange();
            objRange.Start = DateTime.Now;
            objRange.RecursUntil = DateTime.Now.AddDays(4);//add 4 reccurence for today
 
 
            DailyRecurrenceRule objDailyRecurrenceRule = new DailyRecurrenceRule(RecurrenceDay.EveryDay, objRange);
            objDailyRecurrenceRule.Exceptions.Add(DateTime.Now);//add 1  exception for the first recurrence
 
 
 
 
            objAppt.RecurrenceRule = objDailyRecurrenceRule.ToString();
 
 
            lstAppt.Add(objAppt);
 
 
            objAppt = new Appointment();
            objAppt.Start = DateTime.Now.AddHours(3);
            objAppt.End = DateTime.Now.AddHours(4);
            objAppt.Description = "Good Bye";
            objAppt.ID = 2;
            objAppt.RecurrenceParentID = 2;
            lstAppt.Add(objAppt);
 
 
            RadScheduler1.DataSource = lstAppt;
            RadScheduler1.DataBind();

1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 29 Jun 2011, 04:06 PM
Hello Gary,

It seems that the problem was that the time you were trying to set for the first recurrence exception was different from the one at the appointment. Here is the code that should work for you:
List<Appointment> lstAppt = new List<Appointment>();
      Appointment objAppt;
      objAppt = new Appointment();
      objAppt.Start = DateTime.Now;
      objAppt.End = DateTime.Now.AddHours(1);
      objAppt.Description = "Hello World";
      objAppt.ID = 1;
      objAppt.RecurrenceParentID = 1;
 
      RecurrenceRange objRange = new RecurrenceRange();
      objRange.Start = objAppt.Start;
      objRange.RecursUntil = DateTime.Now.AddDays(4);//add 4 reccurence for today
 
 
      DailyRecurrenceRule objDailyRecurrenceRule = new DailyRecurrenceRule(RecurrenceDay.EveryDay, objRange);
      objDailyRecurrenceRule.Exceptions.Add(objAppt.Start);//add 1  exception for the first recurrence

The problem that you experience was most likely caused by the fact that DateTime.Now has different value for each line of code (even though infinitesimally small, that difference still matters).

Kind regards,
Plamen Zdravkov
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Scheduler
Asked by
Gary
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or