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

How do I set the background color and image of a TreeView node?

2 Answers 419 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 16 Sep 2011, 10:59 AM
Hi all,

I'm trying to set both the background color and image of a TreeView node by binding to fields that are returned in my datasource.

In the sample code beneath, the CssClass is correctly bound and my background color is set as required. However, the treenode image is NOT correctly displayed.

<telerik:RadTreeView ID="RadTreeView3" runat="server" DataSourceID="dsTreeSQL" DataFieldID="UniqueId"
    DataFieldParentID="parentid" DataTextField="NodeText" >
    <ContextMenus>
    </ContextMenus>                   
    <DataBindings>                       
        <telerik:RadTreeNodeBinding CssClassField="CssClass" />
        <telerik:RadTreeNodeBinding ImageUrlField="ImageURL" />
    </DataBindings>
</telerik:RadTreeView>

If I reverse the data bindings so that they look like this, the treenode image is correctly applied but the CSS class is not applied.

<DataBindings>                       
    <telerik:RadTreeNodeBinding ImageUrlField="ImageURL" />
    <telerik:RadTreeNodeBinding CssClassField="CssClass" />
</DataBindings>

Is there anything that I can do to apply both a treenode image and CSS class?

The important thing for me is to be able to apply a treenode *background color* and image so any suggestions of how to work around this (perhaps by not using a CSS class) would be appreciated.

Many thanks,
Tim

2 Answers, 1 is accepted

Sort by
0
Accepted
Kevin
Top achievements
Rank 2
answered on 16 Sep 2011, 01:24 PM
Hello Tim,

From what I'm understanding from your situation, is that you want the CssClass and ImageUrlField applied to all nodes. If that is the case then I can understand why it doesn't work as expected. The reason is that you added two RadTreeNodeBinding statements and since you didn't set the Depth property, the first one overrides the second one, so it will apply the first binding to all the items.

If you want to set the CssClass and ImageUrlField to all items, then you should have only one RadTreeNodeBinding statement and set both properties there. Otherwise, you should set the Depth property, if you want a different setting for each level.

I hope that helps.
0
Tim
Top achievements
Rank 1
answered on 16 Sep 2011, 01:42 PM
Hi Kevin,

Thanks for pointing me in the right direction. I didn't really understand how RadTreeNodeBinding and the syntax that I actually needed was this.

<telerik:RadTreeNodeBinding CssClassField="CssClass"  ImageUrlField="ImageURL" />

Thanks again for your help on this - it's much appreciated!

Tim
Tags
TreeView
Asked by
Tim
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Tim
Top achievements
Rank 1
Share this question
or