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

Prevent user from selecting dates

3 Answers 100 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
J
Top achievements
Rank 1
J asked on 01 Jun 2009, 12:06 AM
Hi,

I have a calendar date picker control which the user can select a single date from or multiple dates.

Is it possible to render particular dates as read only so that the user is unable to select those dates?  I'd like to be able to pass either a date or range of dates to the date picker which the user will be unable to select.

Thanks.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Jun 2009, 06:34 AM
Hello,

You can check for the condition and then try out the same logic as shown in the code below:
aspx:
<telerik:RadDatePicker ID="RadDatePicker1" runat="server"
        <Calendar runat="server" OnDayRender="Calendar_OnDayRender" >        
        </Calendar> 
</telerik:RadDatePicker> 

c#:
 protected void Calendar_OnDayRender(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e) 
    { 
        if (e.Day.Date.DayOfWeek == DayOfWeek.Sunday) //check for your condition here 
        { 
            e.Cell.Controls.Clear();            
 
            Label label = new Label(); 
            label.Text = e.Day.Date.Day.ToString(); 
            e.Cell.Controls.Add(label); 
 
            RadCalendarDay calendarDay = new RadCalendarDay(); 
            calendarDay.Date = e.Day.Date; 
            calendarDay.IsSelectable = false
 
            RadDatePicker1.Calendar.SpecialDays.Add(calendarDay); 
        } 
    } 

Thanks
Princy.
0
J
Top achievements
Rank 1
answered on 19 Jun 2009, 12:29 AM
Thanks for this.

But I am also trying to change the look of the days that are not selectable but am having no luck.

I would like to change the TEXT colour so that it is greyed out.

I tried the following on the server side in the RadCalendar1_DayRender event handler:

e.Cell.Style[

"color"] = "gray";

But it doesn't make any changes to the text. 

In the RadCalendar1_DayRender event handler I set the dates to disabled and tried adding the following in the declaration on the aspx page:

 

<

 

DisabledDayStyle ForeColor="Gray" />

But this doesn't work either.

Can you please tell me what I need to do to change the TEXT colour of a date that I have disabled?

0
Princy
Top achievements
Rank 2
answered on 19 Jun 2009, 07:32 AM
Hi,

Using the above code adds labels to the calendar cells. So you would have to add styles to the label control as shown below:
c#:
 protected void Calendar1_DayRender(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e) 
    { 
        if (e.Day.Date.DayOfWeek == DayOfWeek.Sunday)  
        { 
            e.Cell.Controls.Clear(); 
 
            Label label = new Label(); 
            label.Text = e.Day.Date.Day.ToString(); 
            label.BackColor = System.Drawing.Color.Gray; 
            label.ForeColor = System.Drawing.Color.White; 
            e.Cell.Controls.Add(label); 
            
 
            RadCalendarDay calendarDay = new RadCalendarDay(); 
            calendarDay.Date = e.Day.Date; 
            calendarDay.IsSelectable = false
 
            RadDatePicker1.Calendar.SpecialDays.Add(calendarDay); 
        }  
    } 
 
Regards
Princy :)
Tags
Calendar
Asked by
J
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
J
Top achievements
Rank 1
Share this question
or