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

Changing ImageUrl based on custom collection databinding

1 Answer 101 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 07 Sep 2008, 06:43 PM


I am binding a tree to a collection of objects. When the tree is rendered, I would like to display different images before the text of the node,
depending on the type of the node being bound.

I am trying to use the ImageUrlField property to do this, and I receive the following error:

Could not bind to the 'ImageUrlType' property (specified by ImageUrl) while databinding.  Please check the DataBindings fields.

(Otherwise the binding, and the hierarchical view works)
The hierarchy model is implemented based on the following example:
http://www.telerik.com/community/forums/thread/b311D-bdachc.aspx

Here is my code:
Tree.aspx 
        <telerik:RadTreeView ID="RadTreeView1" runat="server" AllowNodeEditing="True"  
            BorderColor="Black" EnableDragAndDrop="True"             
            OnNodeDrop="RadTreeView1_NodeDrop" 
            Skin="Telerik"  
            BorderStyle="Solid" BorderWidth="1px" Height="200px"  
            MultipleSelect="True" onnodeclick="RadTreeView1_NodeClick" Width="280px"
             
            <DataBindings> 
            <telerik:RadTreeNodeBinding 
                  ImageUrlField="ImageUrlType" 
                  /> 
            </DataBindings> 
            .... 

Tree.aspx.cs: 
 
                List<TreeNode> myTreeNodes = new List<TreeNode>(); 
                 
                ... 
 
                RadTreeView1.DataSource = new HierarchicalModelDataSource<TreeNode> { DataSource = myTreeNodes }; 
                RadTreeView1.DataBind(); 
                RadTreeView1.CollapseAllNodes(); 

TreeNode.cs: 
    public class TreeNode : IModelWithHierarchy<TreeNode> 
    { 
        CoreData _coreData; 
        public CoreData CoreDataItem 
        { 
            get { return _coreData; } 
            set { _coreData = value; } 
        } 
 
 
        public TreeNode Parent { get; set; } 
        public List<TreeNode> Children { get; set; } 
 
        public string Name 
        { 
            get 
            { 
                return _coreData.Name; 
            } 
 
            set 
            { 
                ; 
            } 
        } 
         
         
        public string ImageUrlType 
        { 
        get 
        { 
            String directoryImageUrl = "Images/folder.gif"
            String fileImageUrl = "Images/image.png"
 
            if (_coreData.IsDirectory) 
            { 
            return directoryImageUrl; 
            } 
            else if (_coreData.IsFile) 
            { 
            return fileImageUrl; 
            } 
        } 
         }         
    } 

Thank you,
Alex


1 Answer, 1 is accepted

Sort by
0
Alex
Top achievements
Rank 1
answered on 07 Sep 2008, 10:31 PM
I found a workaround (thanks TelerikTrainer!) :

        protected void RadTreeView1_NodeDataBound(object sender, RadTreeNodeEventArgs e) 
        { 
            TreeNode treeNode = (treeNode)e.Node.DataItem; 
            e.Node.ImageUrl = treeNode.ImageUrlType; 
        } 


but still curious why ImageUrlField is not working declaratively?
Tags
TreeView
Asked by
Alex
Top achievements
Rank 1
Answers by
Alex
Top achievements
Rank 1
Share this question
or