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

Problem with image icons in TreeView

1 Answer 174 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Igor Ashmetkov
Top achievements
Rank 1
Igor Ashmetkov asked on 09 Oct 2008, 11:49 AM
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>

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 10 Oct 2008, 06:42 AM
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.
Tags
TreeView
Asked by
Igor Ashmetkov
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or