[CLOSED] Programmatically change root text in Treepanel control

  1. #1

    [CLOSED] Programmatically change root text in Treepanel control

    Hello,

    Is this possible to do from the code-behind for a page?

    I have a treepanel similar to the following:

                <ext:TreePanel ID="tree" runat="server" Title="My Tree Panel" Border="false" Width="340"
                    AutoScroll="true" UseArrows="true" ContainterScroll="true">
                    <Root>
                        <ext:AsyncTreeNode NodeID="0" Text="Root" />
                    </Root>
                    <Loader>
                        <ext:PageTreeLoader OnNodeLoad="NodeLoad">
                        </ext:PageTreeLoader>
                    </Loader>
                </ext:TreePanel>
    
        Protected Sub NodeLoad(ByVal sender As Object, ByVal e As NodeLoadEventArgs)
    
            If e.NodeID = 0 Then
               'Would like to do something like
               'e.Text = "My Text"
            End If
    
    
        End Sub
    -Eric
    Last edited by Daniil; Nov 24, 2010 at 6:56 AM. Reason: [CLOSED]
  2. #2
    Quote Originally Posted by ewgoforth View Post
    Hello,

    Is this possible to do from the code-behind for a page?

    I have a treepanel similar to the following:

                <ext:TreePanel ID="tree" runat="server" Title="My Tree Panel" Border="false" Width="340"
                    AutoScroll="true" UseArrows="true" ContainterScroll="true">
                    <Root>
                        <ext:AsyncTreeNode NodeID="0" Text="Root" />
                    </Root>
                    <Loader>
                        <ext:PageTreeLoader OnNodeLoad="NodeLoad">
                        </ext:PageTreeLoader>
                    </Loader>
                </ext:TreePanel>
    
        Protected Sub NodeLoad(ByVal sender As Object, ByVal e As NodeLoadEventArgs)
    
            If e.NodeID = 0 Then
               'Would like to do something like
               'e.Text = "My Text"
            End If
    
    
        End Sub
    -Eric
    I fixed this with a mix of javascript and code-behind.
  3. #3
    Can you post a code sample demonstrating how you solved the problem? Others might be interested in the solution and we might be able to offer some feedback.
    Geoffrey McGill
    Founder & CEO
  4. #4
    Quote Originally Posted by geoffrey.mcgill View Post
    Can you post a code sample demonstrating how you solved the problem? Others might be interested in the solution and we might be able to offer some feedback.
    Here's a simplified example of what I've got:

    <ext:TreePanel ID="tree" runat="server" Title="Req Classes" Border="false" Width="340"
        AutoScroll="true" UseArrows="true" ContainterScroll="true">
        <Root>
            <ext:AsyncTreeNode NodeID="0" Text="Root" Expanded="true" />        
        </Root>
        <Listeners>
            <BeforeLoad Fn="nodeLoad" />
        </Listeners>
    </ext:TreePanel>
    
                        
        <ext:Hidden ID="myRootNode" runat="server" />
    
    <script>
    // load node          
     function nodeLoad(node) {
    
                if (node.id=='0') node.setText(#{myRootNode}.getValue());
    
                
                  Ext.net.DirectMethods.NodeLoad(node.id, {
                     success: function (result) {
                        Ext.Msg.alert('Success');
                    },
                    failure: function (errorMsg) {
                        Ext.Msg.alert('Failure', errorMsg);
                    }
                });            
    
    
                }
         </script>
    In the init event of my page I have something like:

    hdnRootNode.Value = "newroot"
    tree.CollapseAll() tree.ReloadAsyncNode("0", Nothing) stoMyStore.RemoveAll() Dim nodes As New Ext.Net.TreeNodeCollection() stoMyStore.AddRecord(oRootObject, True)
    Dim asyncNode As New AsyncTreeNode()
    asyncNode.Text = oRootObject.SI_NAME asyncNode.NodeID = oRootObject.SI_ID nodes.Add(asyncNode)
    I then have the following direct method.

    <DirectMethod()> _
    Public Function NodeLoad(ByVal nodeID As String) As String
    
        Dim nodes As New Ext.Net.TreeNodeCollection()
    
    End Function
  5. #5
    Hi,

    Here is another way to achieve this.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!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>Ext.NET Example</title>
     
        <script runat="server">
            protected void NodeLoad(object sender, NodeLoadEventArgs e)
            {
                Ext.Net.TreeNode treeNode = new Ext.Net.TreeNode();
                treeNode.Leaf = true;
                e.Nodes.Add(treeNode);
                TreePanel1.CallNode("setText", e.NodeID, "new text");
            }
        </script>
     
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:TreePanel 
            ID="TreePanel1" 
            runat="server" 
            Title="Tree" 
            AutoHeight="true">
            <Loader>
                <ext:PageTreeLoader OnNodeLoad="NodeLoad" />
            </Loader>
            <Root>
                <ext:AsyncTreeNode Text="Root" />
            </Root>
        </ext:TreePanel>
        </form>
    </body>
    </html>

Similar Threads

  1. TreePanel without Root node
    By Dominik in forum 1.x Help
    Replies: 3
    Last Post: Jun 25, 2014, 7:07 PM
  2. [CLOSED] TreePanel Clear Root Nodes, Add More from AjaxMethod
    By davidhoyt in forum 1.x Premium Help
    Replies: 9
    Last Post: Jun 25, 2014, 4:33 PM
  3. TreePanel - load root with loader
    By pintun in forum 1.x Help
    Replies: 2
    Last Post: Apr 14, 2010, 8:19 PM
  4. Retrieve treepanel's root after reload
    By whitvanilla in forum 1.x Help
    Replies: 0
    Last Post: Jun 04, 2009, 9:28 AM
  5. [CLOSED] TreePanel + AjaxMethod + AsyncNode + Root
    By state in forum 1.x Premium Help
    Replies: 6
    Last Post: May 08, 2009, 8:01 AM

Posting Permissions