Change back-color of appointments based on a value

2 posts, 0 answers
  1. Fazal
    Fazal avatar
    1 posts
    Member since:
    Sep 2010

    Posted 08 Feb 2011 Link to this post

    hello everyone,
    I have stuck on the issue of changing the background color of rad-scheduler appointments, based on a value. My scenario is as,
    I have a class named as <appointments> which contains the following properties StartDate,EndDate,TaskId,TaskName and Status.
    The appointments class is the data source of scheduler.
    I want to change the background -color of appointments compairing the values in status field, but at the same time status should not be shown.
    advance thnx.

    scheuler.ascx
    <telerik:RadScheduler ID="calTaskDisplay" runat="server" DataEndField="EndDate" DataKeyField="TaskId"
                        DataStartField="EndDate" DataSubjectField="TaskName" OnAppointmentCreated="calTaskDisplay_AppointmentCreated"
                        OnDataBound="calTaskDisplay_DataBound" AllowDelete="False" AllowEdit="False" SelectedView="MonthView"
                        DayStartTime="09:00:00" DisplayDeleteConfirmation="False" EditFormDateFormat="d/M/yyyy"
                        EnableAdvancedForm="False" EnableViewState="False" FirstDayOfWeek="Monday" LastDayOfWeek="Friday"
                        WorkDayEndTime="17:00:00" EnableCustomAttributeEditing="true" CustomAttributeNames="status"
                        WorkDayStartTime="09:00:00" OnAppointmentDataBound="calTaskDisplay_AppointmentDataBound">
                        <DayView DayStartTime="09:00:00" ShowHoursColumn="False" WorkDayEndTime="17:00:00" />
                        <WeekView DayStartTime="09:00:00" WorkDayStartTime="09:00:00" WorkDayEndTime="17:00:00" />
                        <AppointmentTemplate>
                            <%#Eval("Subject")%>
                            <input type="text" id="lblStatus" visible="false" title='<%# Eval("Status") %>' />
                        </AppointmentTemplate>
                    </telerik:RadScheduler>

    codebehind as,
    scheduler.ascx.cs
    Page_Load()
    {
    List<ScheduledTasks> loOtherTasks = loClient.GetScheduledTasks(Session["UserId"].ToString());
                    calTaskDisplay.DataSource = loOtherTasks;
                    calTaskDisplay.DataBind();
    }
    calTaskDisplay_AppointmentDataBound(object sender, SchedulerEventArgs e)
    {
     switch (e.Appointment.Attributes["Status"])
                {
                    case "Pending": e.Appointment.BackColor = System.Drawing.Color.Red;
                        break;
                    case "pending": e.Appointment.BackColor = System.Drawing.Color.Red;
                        break;
                    case "Complete": e.Appointment.BackColor = System.Drawing.Color.Green;
                        break;
                    case "complete": e.Appointment.BackColor = System.Drawing.Color.Green;
                        break;
                    case "Over due": e.Appointment.BackColor = System.Drawing.Color.Red;
                        break;
                    case "over due": e.Appointment.BackColor = System.Drawing.Color.Red;
                        break;
                    case "Started": e.Appointment.BackColor = System.Drawing.Color.Blue;
                        break;
                    case "started": e.Appointment.BackColor = System.Drawing.Color.Blue;
                        break;
                    default:
                        break;
    }
     
    calTaskDisplay_DataBound(object sender, EventArgs e)
    {
    foreach (ResourceType resType in calTaskDisplay.ResourceTypes)
                {
                    resType.AllowMultipleValues = false;
                }
    }
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Feb 2011 Link to this post

    Hello Fazal,


    You can directly access the "status" value instead of adding it in AppointmentTemplate part.

    Try the following code:
    protected void RadScheduler1_AppointmentDataBound(object sender, SchedulerEventArgs e)
    {
        DataRowView row = (DataRowView)e.Appointment.DataItem;
        string status = row["Subject"].ToString();
       // Now check for your condition
    }



    Thanks,
    Princy.
Back to Top