Problem with image icons in TreeView

2 posts, 0 answers
  1. Igor Ashmetkov
    Igor Ashmetkov avatar
    12 posts
    Member since:
    Oct 2008

    Posted 09 Oct 2008 Link to this post

    Hello. I have this code to change image icons in the TreeView by client-side.
    When I press button - icons are changes (to "image.gif"), but when I select row 1, 2 or 3 there icons are change back to "folder.gif". What I need to do to stay icons "image.gif" after selecting TreeView row?
    Thanks


    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="treeViewSetImage.aspx.cs"
        Inherits="treeViewSetImage" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server" />
            <div>
                <telerik:RadTreeView ID="tvwUserWorkout" runat="server">
                    <Nodes>
                        <telerik:RadTreeNode Text="node1" ImageUrl="Images/folder.gif" />
                        <telerik:RadTreeNode Text="node2" ImageUrl="Images/folder.gif" />
                        <telerik:RadTreeNode Text="node3" ImageUrl="Images/folder.gif" />
                        <telerik:RadTreeNode Text="node4" />
                        <telerik:RadTreeNode Text="node5" />
                    </Nodes>
                 </telerik:RadTreeView>   
            </div>
            <input type="button" onclick="OnNodeEdited('new text','Images/image.gif')" value="Change image and text" />
        </form>

        <script type="text/javascript">
            function OnNodeEdited(nodetext,imageurl)   
            {
                var tree = $find("<%= tvwUserWorkout.ClientID %>");    
                tree.trackChanges();        
                for (var i = 0; i < tree.get_nodes().get_count(); i++) {   
                    var node = tree.get_nodes().getNode(i);        
                    node.set_imageUrl(imageurl);         
                    node.set_text(nodetext);            
                      
                }                
                tree.commitChanges();         
            }   
        </script>

    </body>
    </html>
  2. Yana
    Admin
    Yana avatar
    4813 posts

    Posted 10 Oct 2008 Link to this post

    Hello,

    Please modify OnNodeEdited method like this:

    function OnNodeEdited(nodetext,imageurl)     
    {   
      var tree = $find("<%= tvwUserWorkout.ClientID %>");      
      tree.trackChanges();          
      for (var i = 0; i < tree.get_nodes().get_count(); i++) {     
        var node = tree.get_nodes().getNode(i);          
        node.set_imageUrl(imageurl);           
        node.set_text(nodetext);              
        node.set_selectedImageUrl(imageurl);  
      }                  
      tree.commitChanges();  

    Regards,
    Yana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top