Back to Devexpress

TreeViewNode.Image Property

aspnet-devexpress-dot-web-dot-treeviewnode-848e8062.md

latest3.0 KB
Original Source

TreeViewNode.Image Property

Gets the settings of a node’s image.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public ItemImageProperties Image { get; }
vb
Public ReadOnly Property Image As ItemImageProperties

Property Value

TypeDescription
ItemImageProperties

A ItemImageProperties object that contains image settings.

|

Remarks

The Image property provides access to the settings that define an image displayed within the node. The specified image can be used as a link if the ASPxTreeView.NodeLinkMode property is set to the TextAndImage or ContentBounds value.

In order to assign the same image to all nodes within an ASPxTreeView, the TreeViewImages.NodeImage can be used.

Example

The code below demonstrates how you can define node images and change them, when expanding and collapsing nodes on the client side.

csharp
using DevExpress.Web.ASPxTreeView;

public partial class _Default : System.Web.UI.Page {
    protected void Page_Load(object sender, EventArgs e) {
       DataBind();
       DefineImages(ASPxTreeView1.Nodes);
    }
    protected void DefineImages(TreeViewNodeCollection nodes) {
        foreach (TreeViewNode node in nodes) {
            if (node.Nodes.Count > 0) {
                node.Image.Url = "~/Images/closed_folder.png";
                DefineImages(node.Nodes);
            }
            else {
                node.Image.Url = "~/Images/file.png";
            }
        }
    }
}
aspx
<dx:ASPxTreeView ID="ASPxTreeView1" runat="server" DataSourceID="XmlDataSource1">
<ClientSideEvents ExpandedChanged="function(s, e) {
    if (e.node.GetExpanded()){
        e.node.SetImageUrl('Images/opened_folder.png');
    }
    else {
        e.node.SetImageUrl('Images/closed_folder.png');
    }
}"/>
</dx:ASPxTreeView>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/Site.xml"
            XPath="/mainmenu/*"></asp:XmlDataSource>

See Also

Tree View

TreeViewNode Class

TreeViewNode Members

DevExpress.Web Namespace