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

RadCalendar IsSelected ignored

3 Answers 61 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Jeff Paetkau
Top achievements
Rank 1
Jeff Paetkau asked on 17 Jun 2010, 12:25 AM
Hi,

It seems that the RadCalendar.IsSelected property is ignored. The below code should randomly select 1 of every 5 days. Instead none are selected. Any help is appreciated.

Jeff

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title></title
</head> 
<body> 
    <form id="form1" runat="server"
        <asp:ScriptManager runat="server" /> 
        <rad:RadCalendar runat="server" OnDayRender="OnDayRender" EnableMultiSelect="true" /> 
    </form> 
</body> 
</html> 
 

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
 
public partial class _Default : System.Web.UI.Page 
    private Random Rand = new Random(); 
 
    protected void OnDayRender(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e) 
    { 
        if (Rand.Next(5) == 0) 
            e.Day.IsSelected = true
    } 

3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 22 Jun 2010, 10:52 AM
Hello Jeff Paetkau,

I would suggest that you review the following forum threads:

Forum1
Forum2

I hope this helps,
Martin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jeff Paetkau
Top achievements
Rank 1
answered on 22 Jun 2010, 05:03 PM
Hi,

From one of the threads:
"You might be adding the special day too late in the life cycle of the control"

Which is what I figured. You just have to use some other logic on Page_Load or something to make it work.

Might I suggest adding OnDayPreRender or OnDayLoad events. I think they would be very useful.

Jeff
0
Martin
Telerik team
answered on 23 Jun 2010, 04:00 PM
Hello Jeff Paetkau,

I am afraid that we do not plan to implement similar events in the near future. Based on that I would suggest that you use the following approach:

Markup:

<asp:ScriptManager ID="ScriptManager2" runat="server" />
<telerik:radcalendar runat="server" ID="RadCalendar1"
    enablemultiselect="true" onprerender="RadCalendar1_PreRender" />

Code-behind:

private Random Rand = new Random();
protected void RadCalendar1_PreRender(object sender, EventArgs e)
{
    for (DateTime date = RadCalendar1.CalendarView.ViewStartDate; date <= RadCalendar1.CalendarView.ViewEndDate; date = date.AddDays(1))
    {
        if (Rand.Next(5) == 0)
        {
            RadCalendar1.SelectedDates.Add(new RadDate(date.Date));
        }
    }
}

I hope this helps.

All the best,
Martin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Calendar
Asked by
Jeff Paetkau
Top achievements
Rank 1
Answers by
Martin
Telerik team
Jeff Paetkau
Top achievements
Rank 1
Share this question
or