首页 > 解决方案 > 如何以编程方式在sitecore中选择树列表项

问题描述

我在内容项中有一个办公室位置树列表,我必须以编程方式选择一个位置。怎么做...任何信息

标签: sitecoreprogrammaticallytreelist

解决方案


我们以编程方式将文本值设置到站点核心字段的方式与多列表或树列表任何字段类似。唯一的区别在于树列表和多列表内容 ID 是管道分隔的,例如 {GUID for office location 1}|{GUID for office location 2}

因此,您需要编辑树列表字段,如下所示:

using (new Sitecore.SecurityModel.SecurityDisabler())
{

  Item item = master.GetItem("path of your item");
  if (item !=null)
  {
    item.Editing.BeginEdit();
    item["Office Location Treelist fieldname"] = "{40764AF5-F3C9-4B36-8B51-3EF36702E3DB}|{406200EB-E5D5- 
                                47FB-9031-8A49A7C8FC06}";   
                 // Make sure these item ids belong to datasource of your treelist
    item .Editing.EndEdit();
  }

推荐阅读