Question

I have folder in Kentico CMS containing few items. Everything inside the folder is one document type. I would like to bind name of every item in this folder to drop down but I have no idea how to get data from Kentico.

Was it helpful?

Solution

Assuming you are creating a new control you put following into the markup:

<asp:DropDownList runat="server" ID="drpItems"/>

And following into the codebehind:

TreeProvider treeProvider = new TreeProvider(SiteContext.CurrentUser);
TreeNodeDataSet docs = DocumentHelper.GetDocuments("YourSite", "/%", "en-US", true, TreeProvider.ALL_CLASSNAMES, null, "DocumentName", TreeProvider.ALL_LEVELS, false, -1, "DocumentName, DocumentID", treeProvider);
foreach (TreeNode treeNode in docs)
{
    drpItems.Items.Add(new ListItem
    {
        Text = treeNode.DocumentName,
        Value = treeNode.DocumentID.ToString()
    });
 }

Adjust parameters of the DocumentHelper.GetDocuments() methods - espcially siteName, nodeAliasPath and columns you want to select.

If you don't use workflow/versioning you can use SelectNodes() method from the treeProvider. It has similar parameters and is more efficient for that case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top