Prevent user from selecting dates

4 posts, 0 answers
  1. J
    J avatar
    11 posts
    Member since:
    May 2009

    Posted 31 May 2009 Link to this post

    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.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 01 Jun 2009 Link to this post

    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.
  3. J
    J avatar
    11 posts
    Member since:
    May 2009

    Posted 18 Jun 2009 Link to this post

    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?

  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Jun 2009 Link to this post

    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 :)
Back to Top