Kentico 10 中自定义 Table 中字段的访问列表选项

Access List Options for a Field in a Custom Table in Kentico 10

我有一个自定义 table,其中有几个字段具有列表选项,供用户在添加内容时 select 使用。 API 中是否有一些东西允许我访问特定字段的选项,以便我可以在过滤小部件中使用这些相同的选项?

类似下面的内容,但适用于自定义 table 中的字段?

var guids = ParentDocument.GetValue("CustomFieldName").Split(';');
var referencedDocs = DocumentHelper.GetDocuments().WhereIn("DocumentGuid", guids);

UPDATE - 答案中的 link 发生变化时的代码:

  protected string[] GetFormFieldOptions()
    {
        DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo("custom.MyPageTypeName");
        if (dci != null)
        {
            //Get the data from the form field
            FormInfo fi = new FormInfo(dci.ClassFormDefinition);
            FormFieldInfo ffi = fi.GetFormField("Industry");
            string[] industries = ffi.Settings["Options"].ToString().Split('\n'); 
            return industries;
        }
        return null;
    }

您可以使用与问题中相同的代码。不同之处在于您需要获得 "Page" 或 "Document" 级别不可用的 2 个不同的东西:

  1. 自定义 table 对象
  2. 自定义 table 项基于 #1

您使用 API 获得自定义 table 物品:

var cti = CustomTableItemProvider.GetItem(<id or guid>, "yourcustom.tableclassname);
if (cti != null)
{
    string[] s = ValidationHelper.GetString(cti.GetValue("YourField"), "").Split(";");
}

更新
要在字段中获取动态选项列表,您可以简单地使用列表控件(如下拉列表或单选按钮列表)作为控件(相对于文本框)。然后在下拉列表的属性中,您可以将其设置为查询。在查询中输入类似

的内容
-- if you wan to have a 'select one' add this
SELECT '', '-- select one --'
UNION
SELECT ItemID, FieldName
FROM CustomTable_Name
ORDER BY 2

使用 DataClass InfoProvider 获取您需要的数据。检查 this blog post 以查看更多详细信息。