代码之家  ›  专栏  ›  技术社区  ›  Aaron Powell

根据页面属性显示图标

  •  1
  • Aaron Powell  · 技术社区  · 16 年前

    在SharePoint(Moss 2007)网站的内容类型上,如果属性是某个值,我希望显示一个图标。

    该列是“是/否”,因此所选值应该相当容易确定。

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

    3 回复  |  直到 16 年前
        1
  •  1
  •   Jason    16 年前

    您需要从列表中的项目中获取值。从上面看,我认为这是可行的:

    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
    }
    
        2
  •  0
  •   Nat    16 年前

    我会附和EvilgoatBob的评论吗?在这种情况下,用XSLT显示通常要容易得多。 如果这在您的情况下不合适,编码解决方案可能会起作用。 如果要在表单条目页上显示,可以尝试 custom field control

    这将更容易在使用字段的任何位置一致地显示图标。

        3
  •  0
  •   Aaron Powell    16 年前

    我已经知道怎么做了:

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