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

Setting Style for Appointment

1 Answer 104 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 16 Jun 2009, 10:36 PM
Hi,

I want to be able to set a different style for my appointments and I have read the documentation to find out how to do this. My issue is that I do not want to set the style based on any of the "base" properties of my data source.

I have created my own object and have included the necessary properties for it to be considered an "appointment" and bound the datasource of the scheduler to a list of these objects.

The example I am following shows the overriding of the OnAppointmentCreated handler and then switching on the "subject" in order to set the CssClass property of the appointment object. So my question is - can I use a different property that I have in my custom "appointment" object to switch on? For example, I have a Rating property in my class and would like to check this property in order to set the CssClass property. Can this be done?

Any help is greatly appreciated,
Dan

1 Answer, 1 is accepted

Sort by
0
Accepted
Peter
Telerik team
answered on 17 Jun 2009, 08:20 AM
Hi Dan,

Of course, this can be done easily. You can use any property of the appointment to set the CssClass property. Not only this - you can also use custom attributes.

Referring to the Binding to Generic List demo, you can add a custom attribute by modifying the AppointmentInfo class like this:
class AppointmentInfo  
    {  
        private readonly string _id;  
        private string _subject;  
        private DateTime _start;  
        private DateTime _end;  
        private string _myCustomAttribute;  
        private string _recurrenceRule;  
        private string _recurrenceParentId;  
        private int? _userID;  
 
        public string ID  
        {  
            get { return _id; }  
        }  
 
        public string MyCustomAttribute  
        {  
            get { return _myCustomAttribute; }  
            set { _myCustomAttribute = value; }  
        }  
 
 
        public string Subject  
        {  
            get { return _subject; }  
            set { _subject = value; }  
        }  
 
        public DateTime Start  
        {  
            get { return _start; }  
            set { _start = value; }  
        }  
 
        public DateTime End  
        {  
            get { return _end; }  
            set { _end = value; }  
        }  
 
        public string RecurrenceRule  
        {  
            get { return _recurrenceRule; }  
            set { _recurrenceRule = value; }  
        }  
 
        public string RecurrenceParentID  
        {  
            get { return _recurrenceParentId; }  
            set { _recurrenceParentId = value; }  
        }  
 
        public int? UserID  
        {  
            get { return _userID; }  
            set { _userID = value; }  
        }  
 
        private AppointmentInfo()  
        {  
            _id = Guid.NewGuid().ToString();  
        }  
 
        public AppointmentInfo(string subject, string myCustomAttribute, DateTime start, DateTime end,  
            string recurrenceRule, string recurrenceParentID, int? userID)  
            : this()  
        {  
            _subject = subject;  
            _myCustomAttribute = myCustomAttribute;  
            _start = start;  
            _end = end;  
            _recurrenceRule = recurrenceRule;  
            _recurrenceParentId = recurrenceParentID;  
            _userID = userID;  
        }  
 
        public AppointmentInfo(Appointment source)  
            : this()  
        {  
            CopyInfo(source);  
        }  
 
        public void CopyInfo(Appointment source)  
        {  
            Subject = source.Subject;  
            MyCustomAttribute = source.Attributes["MyCustomAttribute"];  
            Start = source.Start;  
            End = source.End;  
            RecurrenceRule = source.RecurrenceRule;  
            if (source.RecurrenceParentID != null)  
            {  
                RecurrenceParentID = source.RecurrenceParentID.ToString();  
            }  
 
            Resource user = source.Resources.GetResourceByType("User");  
            if (user != null)  
            {  
                UserID = (int?) user.Key;  
            }  
            else 
            {  
                UserID = null;  
            }  
        }  
    } 

Here is how to initialize appointments with the modified AppointmentInfo class:
private void InitializeAppointments()  
        {  
            DateTime start = DateTime.UtcNow.Date;  
            start = start.AddHours(6);  
            Appointments.Add(new AppointmentInfo("Take the car to the service""Green", start, start.AddHours(1), string.Empty, null, 1));  
            Appointments.Add(new AppointmentInfo("Meeting with Alex""Blue", start.AddHours(2), start.AddHours(3), string.Empty, null, 2));  
 
            start = start.AddDays(-1);  
            DateTime dayStart = RadScheduler1.UtcDayStart(start);  
            Appointments.Add(new AppointmentInfo("Bob's Birthday""Green", dayStart, dayStart.AddDays(1), string.Empty, null, 1));  
            Appointments.Add(new AppointmentInfo("Call Charlie about the Project""Blue", start.AddHours(2), start.AddHours(3), string.Empty, null, 2));  
 
            start = start.AddDays(2);  
            Appointments.Add(new AppointmentInfo("Get the car from the service""Red", start.AddHours(2), start.AddHours(3), string.Empty, null, 1));  
        } 

Finally, set CustomAttributeNames="MyCustomAttribute"  for RadScheduler.

Now you can access the custom attribute in AppointementDataBound like this:

e.Appointment.Attributes["MyCustomAttribute"];

Feel free to contact us if you have further questions.


Regards,
Peter
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Scheduler
Asked by
Dan
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or