This is a migrated thread and some comments may be shown as answers.

Anyway to populate treeview nodes attributes?

1 Answer 149 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
James Daresta
Top achievements
Rank 1
James Daresta asked on 12 Aug 2011, 03:19 PM
I am trying to figure out a way to take the custom attributes of a FileExplorerItem and populate the attributes of the treeview nodes, but I cannot seem to find th ebest way to do this. The only solution I have seen in my searching is in http://www.telerik.com/community/forums/aspnet-ajax/file-explorer/how-to-get-attributes-on-client-with-explorermode-filetree.aspx. However, that is a real pain because I have 12 custom attributes I could possibly use from my custom provider that allows file browsing access to our Documentum system. I have tried hooking routines into the TreeView control of the FileExplorer, but its not working as I expected. Here is what I have.

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    RadFileExplorer1.TreeView.NodeDataBound += new RadTreeViewEventHandler(RadTreeView_OnNodeDataBound);
}
 
private void FillTreeViewNodesWithAttributes(RadTreeNode node)
{
    FileBrowserItem fileBrowserItem = (FileBrowserItem)node.DataItem;
 
    foreach (string key in fileBrowserItem.Attributes.AllKeys)
    {
        node.Attributes[key] = fileBrowserItem.Attributes[key];
    }
    if (node.Nodes.Count > 0)
    {
        foreach (RadTreeNode childNode in node.Nodes)
        {
            FillTreeViewNodesWithAttributes(childNode);
        }
    }
}

When I step through the code they node gets filled, but the attributes never make to the client side.Consequentially I don't see where the childnodes get databound. There must be something with the way the tree is populated that I am missing.

I am going for now use the approach in the  link above, but it is not ideal.
 

1 Answer, 1 is accepted

Sort by
0
Dobromir
Telerik team
answered on 17 Aug 2011, 01:14 PM
Hi James,

RadFileExplorer is using RadTreeView and RadGrid controls for its folder tree and files grid components. However, RadTreeView does not offer the same functionality as RadGrid to add attributes but you can achieve this by adding them to the nodes manually by handling the treeview's Load event (to add custom attributes to the initially loaded nodes) and NodeExpanded event (to add attributes to the nested nodes), e.g.:
protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    RadFileExplorer1.TreeView.Load += new EventHandler(TreeView_Load);
    RadFileExplorer1.TreeView.NodeExpand += new RadTreeViewEventHandler(TreeView_NodeExpand);
}
 
private void TreeView_Load(object sender, EventArgs e)
{
    RadTreeView tree = sender as RadTreeView;
    AddFileExplorerItemAttributes(tree.Nodes[0], "10");
}
 
private void AddFileExplorerItemAttributes(RadTreeNode node, String value)
{
    node.Attributes.Add("CustomAttribute", value);
    if (node.Nodes.Count > 0)
    {
        for (int i = 0; i < node.Nodes.Count; i++)
        {
            AddFileExplorerItemAttributes(node.Nodes[i], i.ToString());
        }
    }
}
 
void TreeView_NodeExpand(object sender, RadTreeNodeEventArgs e)
{
    for (int i = 0; i < e.Node.Nodes.Count; i++)
    {
        RadTreeNode node = e.Node.Nodes[i];
 
        AddFileExplorerItemAttributes(node, (i*10).ToString());
    }
}

After that you can access these custom attributes on the client from the node's client-side object, e.g.:
node.get_attributes().getAttribute("CustomAttribute");

I hope this helps.

Kind regards,
Dobromir
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
FileExplorer
Asked by
James Daresta
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
Share this question
or