locked
Set Calendar Event Color RRS feed

  • Question

  • Hi,

    How do I programmatically set background color of a Sharepoint Calendar Event cell?

    Thanks!

    Monday, November 5, 2012 5:46 PM

Answers

  • Hi obrienkev,

    Have look at the following blog, through javascript to set background color of calendar event cell,

    http://davidlozzi.com/2012/06/20/customize-the-sharepoint-calendar-colors/

    Regards,

    Kelly Chen

    • Marked as answer by Qiao Wei Sunday, November 18, 2012 2:38 PM
    Tuesday, November 6, 2012 7:54 AM
  • Greetings,

    This can be easilly achievable, we need override "background-color"  of these css classes  "ms-acal-item" & .ms-acal-default-hover

    Like this:-

    .ms-acal-item
    {
    background-color:yellow;
    }

    Now, if you are developing a custom calendar or showing SPCalendarView in your webpart, then we can add CSS styles very easilly from code to the webpart, follow this approach:-

    protected override void Render(HtmlTextWriter writer)
    {
    string InlineStyle = ".classname{property:value;}"
      // <style type="text/css">... inline style ...</style>
    writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/css");
                    writer.RenderBeginTag(HtmlTextWriterTag.Style);
                    writer.Write(InlineStyle);
                    writer.RenderEndTag();
    }
    Hope this helps..

    Mark as Answer if helped!! To be or Not to Be..The question is this only......


    • Edited by Ankur Madaan Tuesday, November 6, 2012 3:30 PM
    • Proposed as answer by Ankur Madaan Tuesday, November 6, 2012 3:31 PM
    • Marked as answer by Qiao Wei Sunday, November 18, 2012 2:38 PM
    Tuesday, November 6, 2012 3:26 PM

All replies

  • "programmatically" as in a Visual Studio project? There is no property for this. There are a number of JavaScript solutions on the web that key off a another column, often a calculated column.

    http://www.bing.com/search?q=sharepoint+calendar+color


    Mike Smith TechTrainingNotes.blogspot.com my SP customization book

    Monday, November 5, 2012 5:54 PM
  • Hi obrienkev,

    Have look at the following blog, through javascript to set background color of calendar event cell,

    http://davidlozzi.com/2012/06/20/customize-the-sharepoint-calendar-colors/

    Regards,

    Kelly Chen

    • Marked as answer by Qiao Wei Sunday, November 18, 2012 2:38 PM
    Tuesday, November 6, 2012 7:54 AM
  • That article uses the perfered approach of using overlays, but is useful only when you want a whole collection of events (one full calendar of events) to share the same color. I.e. The sales calender overlay will be blue, the marketting calendar overlay will be green, etc. If you can to set the color uniquely for an event you will need one of the JavaScript solutions or a third party calendar.


    Mike Smith TechTrainingNotes.blogspot.com my SP customization book

    Tuesday, November 6, 2012 2:36 PM
  • Greetings,

    This can be easilly achievable, we need override "background-color"  of these css classes  "ms-acal-item" & .ms-acal-default-hover

    Like this:-

    .ms-acal-item
    {
    background-color:yellow;
    }

    Now, if you are developing a custom calendar or showing SPCalendarView in your webpart, then we can add CSS styles very easilly from code to the webpart, follow this approach:-

    protected override void Render(HtmlTextWriter writer)
    {
    string InlineStyle = ".classname{property:value;}"
      // <style type="text/css">... inline style ...</style>
    writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/css");
                    writer.RenderBeginTag(HtmlTextWriterTag.Style);
                    writer.Write(InlineStyle);
                    writer.RenderEndTag();
    }
    Hope this helps..

    Mark as Answer if helped!! To be or Not to Be..The question is this only......


    • Edited by Ankur Madaan Tuesday, November 6, 2012 3:30 PM
    • Proposed as answer by Ankur Madaan Tuesday, November 6, 2012 3:31 PM
    • Marked as answer by Qiao Wei Sunday, November 18, 2012 2:38 PM
    Tuesday, November 6, 2012 3:26 PM
  • What color slot on the SharePoint 2013 color palette tool would accomplish this, when using spcolor in composed looks?

    Wednesday, October 21, 2015 10:42 PM