asp.net - Change TreeView expand image programmatically

TreeView expand image url
We can alter the appearance of treeview control by customizing it's displayed images. we can apply our own set of custom images for the different parts of treeview control. in this example code we demonstrate how can you apply custom image for treeview expand image. treeview has a property named ExpandImageUrl. we can set it's value to change the default expand image on treeview control. following example changes the expand image programmatically.
TreeViewExpandImageUrl.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        TreeView1.ExpandImageUrl = "~/Images/ExpandImage.gif";
    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        TreeView1.ExpandImageUrl = "~/Images/ExpandImage1.gif";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to set, change expand image url (ExpandImageUrl) in TreeView</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy">TreeView Example: ExpandImageUrl</h2>
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
        <asp:TreeView 
             ID="TreeView1"
             runat="server"
             DataSourceID="SiteMapDataSource1"
             Width="250"
             ForeColor="DodgerBlue"
             Font-Bold="true"
             Font-Italic="true"
             BorderColor="SkyBlue"
             BorderWidth="2"
             ExpandDepth="1"
             >
        </asp:TreeView>
        <br />
        <asp:Button 
             ID="Button1" 
             runat="server"
             ForeColor="DarkBlue"
             Text="Change Expand Iamge Url"
             Height="45"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
        <asp:Button 
             ID="Button2" 
             runat="server"
             ForeColor="DarkBlue"
             Text="Another Expand Image"
             Height="45"
             OnClick="Button2_Click"
             Font-Bold="true"
             />
    </div>
    </form>
</body>
</html>
Web.sitemap
Web.sitemap source code here.

   


Related asp.net example