Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
75
Custom styles for activities
posted

Is it possible to use different styles (at last background color) for various activities in MonthView or WeekView  in one day?

 

  • 24497
    posted

    Hi Rogin,

    Appointment has Style property, so you may customize it. For more consistant appearance (avoid possible conflicts of autogenerated <style>s), it is preferrable to use CssClass. Below is example.

    aspx:

    <head runat="server">
     
    <title></title>
     
    <style type="text/css">
      
    .redCss{background:red;}
      
    .blueCss{background:#00C0FF;}
     
    </style>
    </
    head>

    aspx.cs:

    protected void Page_Load(object sender, EventArgs e)
    {
     
    this.CreateAppointment(10, 30, "redCss");
     
    this.CreateAppointment(12, 30, "");
     
    this.CreateAppointment(13, 30, "blueCss");
    }

    private void CreateAppointment(int hour, int min, string css)
    {
     
    Appointment appt = new Appointment(this.WebScheduleInfo1);
     
    DateTime now = DateTime.Now;
     appt.StartDateTime =
    new SmartDate(now.Year, now.Month, now.Day, hour, min, 0);
     appt.Duration =
    new TimeSpan(0, 15, 0);
     appt.Key =
    "key" + hour + min;
     appt.ResourceKey =
    this.WebScheduleInfo1.VisibleResources.UnassignedResource.Key;
     
    this.WebScheduleInfo1.Activities.Add(appt);
     appt.Style.CssClass = css;
    }