views:

107

answers:

3

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.

+1  A: 

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
}
Jason
where do you get the ID for the current loaded page?
Slace
I thought you were creating a custom page to display this information, not sure why you'd need a Page ID...
Jason
A: 

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.

Nat
A: 

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
Response.Write(myField.ToString());
Slace