I have an event receiver which adds splistitems from child sites to the parents site list (in a calendar). How do I access the css or style of an splistitem? I am wanting to color code the different child sites to make them distinguishable on the parent sites calendar. I've been researching this for an hour and have found 0 leads. Surely I'm not the first person to try and access the style of a listitem.

Many thanks.

2 Answers 2


SPListItem is a server object and has very little presentation logic associated with it. However, there are a few ways to style this:

  1. You could handle this by subclassing the control that renders the output and using your own control on the page instead of the default.
  2. If the control uses Xslt to render the content, then you could handle it there by applying the css class during the transform.
  3. if the distinguishing value can be determined on the client (perhaps something unique about the URL) then you could also use jQuery to find the items and apply the appropriate class. The downside about this approach is that there is a quarter second or so lag between the page render and the application of the classes.
  • I may have to go with item 3 for simplicity and a tight deadline, but where can I find more information on Item 2? Where/what event does the transform occur and how do you hook in to that event? Many thanks!
    – JR_ATLDev
    Apr 12, 2011 at 21:22
  • I think XsltListViewWebPart is the best way here. You can use any data from server with ParameterBindings, and style your items any imaginable way with Xslt. Apr 12, 2011 at 21:29

Not sure I understand why you would want to find the style of a list item. The styles are defined by the css and all of them would have the same class applied unless you have some custom styling using either custom css, custom master pages, or themes. Why not make it part of your event that you include some metadata around which child site the event is being copied from and then add a calculated column that will color code the item?

  • That is precisely what I am trying to do. Depending on which site the event is firing from I want to add a custom css class or if possible backcolor to the splistitem. How do you access this property?
    – JR_ATLDev
    Apr 12, 2011 at 20:54
  • You'd have to set something up like in the event receiver to set a metadata field or something indicating the site. Then you can use some of the ideas here: nothingbutsharepoint.com/sites/eusp/Pages/…
    – Lori
    Apr 12, 2011 at 21:01
  • Thanks, but your not answering the right question. I know how to get the current site (through the SPItemEventProperties object). However I do not know how to access the splistitem css attribute.
    – JR_ATLDev
    Apr 12, 2011 at 21:13
  • As Dave points out below, getting the class of the item will not help you much, as each item is not given a separate class, you have to find a unique value to that item. Once you have determined the unique value, you would need to write something that would apply conditional formatting to the item, such as JQuery or some other css method.
    – Lori
    Apr 12, 2011 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.