how to programmatically set a value of Treelist in sitecore

℡╲_俬逩灬. 提交于 2019-12-11 12:17:16

问题


I have a job description page, and I am adding values to it programmatically. One of the fields is "Office Locations", with a data type of Treelist. How can I add values to the Treelist so that I can set the office location?


回答1:


Sitecore Treelist stores the ids of selected items in a pipeline separated form.

If you want to set the value of Treelist programmatically you need to set it to a string which looks like:

{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}|{EA015A5F-C41B-4510-B538-438EF204F5E2}

where {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}, {EA015A5F-C41B-4510-B538-438EF204F5E2} and possibly more of the string parts separated with | characters are ids of chosen pages.

using (new EditContext(jobItem))
{
    jobItem["OfficeLocations"] = "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}|{EA015A5F-C41B-4510-B538-438EF204F5E2}";
}


来源:https://stackoverflow.com/questions/18233509/how-to-programmatically-set-a-value-of-treelist-in-sitecore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!