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

Style question

6 Answers 77 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Ben White
Top achievements
Rank 1
Ben White asked on 28 Mar 2010, 10:20 PM
Hi,

I am trying to interact with the calendar control server side (c#)

I collect a number of dates from a database and alter the styling of these date cells. The dates from the database are "busy" dates.

So far I have managed to modify the background colour and fore colour of these cells but am unable to

1. Disable these dates completely so that they do not respond to a mouse click
2. Stop the hover style appearing when they mouse is hovered

Ideally I would like to:

1. Disable particular dates and set their styles on the server side
2. Set individual styling on particular days (like colour, hover style etc)

I am finding it particularly frustrating that there seems to be no server side ability to iterate through the dates and set individual css properties on an individual basis.

Please could you let me know if what I am trying to achieve is possible?

Thanks in advance.

6 Answers, 1 is accepted

Sort by
0
Accepted
robertw102
Top achievements
Rank 1
answered on 29 Mar 2010, 09:03 PM
The way that I add the days to the RadCalendar control is by adding them to SpecialDays collection of the calendar. Here's an example of how I do it:

// create calendar day 
                RadCalendarDay bookedDay = new RadCalendarDay(RadCalendar1); 
                bookedDay.Date = dtBoldDate; 
                bookedDay.ItemStyle.Font.Bold = true
                bookedDay.ItemStyle.CssClass = "BookingNormal";                 
 
                // repeat day only once 
                bookedDay.Repeatable = Telerik.Web.UI.Calendar.RecurringEvents.None; 
 
                 
 
                    // add to special days list 
                    RadCalendar1.SpecialDays.Add(bookedDay); 

The code above just created RadCalendarDay objects and adds them to the SpecialDays collection. In my example I just set the CSSClass used to modify the day's appearance, but you add you own styles as well. If you want to disable the ability of selecting them, which I guess would cause the same effect of disabling them, then you would set the property IsSelectable="false" of the RadCalendarDay object.

I hope that helps.
0
Ben White
Top achievements
Rank 1
answered on 29 Mar 2010, 10:35 PM
I appreciate you taking the time to help.

I am struggleing I think to find relevent documentation. I am using the following code below to add special days in.

I am calling this in the dayrender event but it seems to be inconsistent. For example using the code below the tooltip is not showing up where as if I set the e.Cell.ToolTip property it does show up. Also styles are differently applied (ie. the style assignment only shows up on a rollover)

Very confusing and there seem to be very few "real world" examples available.

RadCalendarDay

 

bookedDay = new RadCalendarDay(RadCalendar1);

 

bookedDay.Date =

new DateTime(e.Day.Date.Year, e.Day.Date.Month, e.Day.Date.Day);

 

bookedDay.ItemStyle.Font.Bold =

true;

 

bookedDay.ItemStyle.CssClass =

"BookingNormal";

 

bookedDay.ToolTip =

"hello";

 

 

// repeat day only once

 

bookedDay.Repeatable = Telerik.Web.UI.Calendar.

RecurringEvents.None;

 

 

// add to special days list

 

RadCalendar1.SpecialDays.Add(bookedDay);

0
Ben White
Top achievements
Rank 1
answered on 30 Mar 2010, 02:04 PM
I'm going to mark this as solved as the advice in essence is correct and helped.
0
robertw102
Top achievements
Rank 1
answered on 30 Mar 2010, 02:24 PM
Is there a reason that your adding the days in the RadCalendar's DayRender event? In my applications I add them in the Page_Load event.
0
Ben White
Top achievements
Rank 1
answered on 30 Mar 2010, 03:03 PM
Wrongly or rightly I am using things like

if

 

(e.Day.IsWeekend){
DayObject.IsSelectable =
false;

 

e.Cell.CssClass =

"MyClassWeekend";

 

e.Cell.ToolTip =

"Mon-Fri only";

 

}
RadCalendar1.SpecialDays.Add(DayObject);

 

 

I use the above to set style and state specific to day types (ie. weekend, booked, available)

I could find any way of iterating through the days collection of the calendar in the Page_Load event. I would have much preferred to do it this way.

I have now posted a full example of the calendar with .txt file links to the code and aspx files so you can see what I mean.
http://gcdemos.co.uk/caltest.aspx

Two days on this and I'm tearing my hair out :(

Now have it to a stage where I can set all of the styles but when I fast nav to a month and then go back, any dates that have been selected lose their style when the hover event occurs.

Going mad so any help much appreciated.

Thanks.

0
Ben White
Top achievements
Rank 1
answered on 30 Mar 2010, 04:17 PM
Further to my last post.

I have found that by setting

RadCalendar1.SpecialDays.Clear();


It will stop the mouse hover removing the selected days.

This is turn though introduces another bug which is that the setting of IsSelectable=false does not work.
If I check a click event on the client side, even after setting as false on the server, the client picks it up as true.
This does not happen when the .Clear() method is not used.

Very strange and unless I'm doing something very wrong then this is a bug.
Tags
Calendar
Asked by
Ben White
Top achievements
Rank 1
Answers by
robertw102
Top achievements
Rank 1
Ben White
Top achievements
Rank 1
Share this question
or