2009-02-04 91 views
1

在SharePoint(MOSS 2007)站点上的内容类型中,如果属性是特定值,我想显示一个图标。根据页面属性显示图标

该列是一个是/否,因此所选值应该很容易确定。

那么我怎样才能在ASPX中显示读取值呢?我知道我需要修改web.config以允许页面内C#,但我不确定如何找到该属性。我想我需要使用SPContext.Current,但我不确定里面有什么。

+0

你有没有考虑使用列表视图Web部件XSLT来实现这个,而不是编写自定义代码? – 2009-02-04 17:42:53

回答

0

嗯,我已经找到了如何做到这一点:

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()); 
1

您需要从列表中的项目中获取值。我认为这将工作:

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 
} 
+0

你在哪里获得当前加载页面的ID? – 2009-02-04 22:14:17

0

我会回应评论EvilGoatBob?因为用XSLT显示通常要容易得多。 如果这不适合您的情况,可以使用代码解决方案。 如果要在表单输入页面上显示,您可以尝试使用custom field control

无论使用哪个字段,都可以更容易地统一显示图标。