sharepoint – Show icon depending on page property – Education Career Blog

On a content type in a SharePoint (MOSS 2007) site I want to show an icon if the property is a certain value.

The column is a Yes/ No so the selected value should be fairly easy to determine.

So how can I, in the ASPX, show read the value? I know I need to modify the web.config to allow for in-page C#, but I’m just not sure how to find the property. I think I need to use SPContext.Current, but I’m not sure what inside that.


you’ll need to get the value from an item in the list. off the top, i think this will work:

SPList list = SPContext.Current.Web.Lists"my list name";
SPListItem item = list.items.GetItemById(ItemId);

//the following 2 lines are not strictly necessary
//but since you explicitly mentioned this is related to ContentTypes
//this is how you can ensure the item you retrieved is of the apprpriate type
SPContentTypeId myContentTypeId = GetContentTypeId();
if (list.ContentTypes.BestMatch(myContentTypeId).Equals(item.ContentType.Id))
  string value = item"interesting field name".ToString();
  //if the value is of interest, do your thing


I would echo the comment by EvilGoatBob? in that displaying by XSLT is usually a lot easier to do.
If that is not appropriate in your situation, a coded solution may work.
If you want to display on the form entry page, you can try a custom field control

This would be easier to consistently display the icon wherever the field is used.


Well I’ve found out how to do this:

var item = SPContext.Current.File.Item; //returns the SPListItem for the current context
var myField = item"SomeFieldName"; //this will throw a NullReferenceException if there is no data for the field yet though

Leave a Comment