[CLOSED] Set selected treenode in code behind

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Set selected treenode in code behind

    Hi,

    Is there a way to search a treenode by its id and then set it as selected node during page_load event?

    thanks,
    Daniel
    Last edited by Daniil; Jan 04, 2011 at 11:52 AM. Reason: [CLOSED]
  2. #2
    Hi Daniel,

    Please use the following code:
    this.TreePanel1.CallNode("select", nodeId);
    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            this.TreePanel1.CallNode("select", "SomeNodeId");
        }
    </script>
    
    <!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>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:TreePanel ID="TreePanel1" runat="server" AutoHeight="true">
            <Root>
                <ext:TreeNode Text="Root (level 0)" Expanded="true">
                    <Nodes>
                        <ext:TreeNode Text="Node1" />
                        <ext:TreeNode NodeID="SomeNodeId" Text="Node2" />
                    </Nodes>
                </ext:TreeNode>
            </Root>
        </ext:TreePanel>
        </form>
    </body>
    </html>
  3. #3
    Hi Danill,

    Thanks for the quick response! We're using version 0.8.2 here (it's a long story). Unless I've misread or misunderstood you, I'm not sure TreePanel has the built-in CallNode method. The scenario that we're looking for is everytime the page load, if there's a selected node id in the session value, we want the treepanel to expand and select the node that matches the node id that being stored in the session value. Hope this help.

    thanks,
    dan
  4. #4
    In 0.8.x I would suggest you the following way:

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            string nodeId = "SomeId"; //get it from Session
            ScriptManager.GetInstance(this.Context).AddScript("selectAndExpand('" + nodeId + "');");  
        }
    </script>
    
    <!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>Coolite 0.8.x Example</title>
        
        <script type="text/javascript">
            var selectAndExpand = function (nodeId)  {
                var node = TreePanel1.getNodeById(nodeId);
                node.expand();
                node.select();
            }
        </script>
    </head>
    <body>
        <form runat="server">
        <ext:ScriptManager runat="server" />
        <ext:TreePanel ID="TreePanel1" runat="server" AutoHeight="true">
            <Root>
                <ext:TreeNode Text="Root" Expanded="true">
                    <Nodes>
                        <ext:TreeNode Text="Node1">
                            <Nodes>
                                <ext:TreeNode Text="Leaf node" Leaf="true" />
                            </Nodes>
                        </ext:TreeNode>
                        <ext:TreeNode NodeID="SomeId" Text="Node2">
                            <Nodes>
                                <ext:TreeNode Text="Leaf node" Leaf="true" />
                            </Nodes>
                        </ext:TreeNode>
                    </Nodes>
                </ext:TreeNode>
            </Root>
        </ext:TreePanel>
        </form>
    </body>
    </html>
  5. #5
    Hi Danill,

    It's failed at the following line in javascript

    var node = TreePanel1.getNodeById(nodeId);
    It didn't like the TreePanel1.getNodeById(...) so I substituted it with
    <%TreePanel1.ClientID%>.getNodeById(..)
    It stopped complaining about the TreePanel1, but i'm getting a dffierent error:

    "...Object doesn't support this property or method..."

    thanks,
    Dan
    Last edited by Daniil; Dec 30, 2010 at 5:13 AM. Reason: Please use [CODE] tags
  6. #6
    Hi,

    Please clarify did you test the same code that I posted or are you trying to apply this in your application? (I guess the second)

    Please provide us with a sample code to reproduce.
  7. #7

    Select node in code behind

    and how can I use it in 2.4 version ???
  8. #8
    Here is an example.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Select(object sender, DirectEventArgs e)
        {
            this.TreeSelectionModel1.Select("Node2");
        }
    </script>
    
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <ext:Button runat="server" Text="Select Node2" OnDirectClick="Select" />
    
            <ext:TreePanel ID="TreePanel1" runat="server">
                <Root>
                    <ext:Node Text="Root" Expanded="true">
                        <Children>
                            <ext:Node NodeID="Node1" Text="Node1" Leaf="true" />
                            <ext:Node NodeID="Node2" Text="Node2" Leaf="true" />
                            <ext:Node NodeID="Node3" Text="Node3" Leaf="true" />
                        </Children>
                    </ext:Node>
                </Root>
                <SelectionModel>
                    <ext:TreeSelectionModel ID="TreeSelectionModel1" runat="server">
                        <SelectedRows>
                            <ext:SelectedRow RecordID="Node1" />
                        </SelectedRows>
                    </ext:TreeSelectionModel>
                </SelectionModel>
            </ext:TreePanel>
        </form>
    </body>
    </html>
  9. #9
    very good , how can i run the associated event ???

    I need to run the specific handler:

    "addTab(#{TabPanel1}," + node.Qtitle + ", " + node.Text + ");";

    after node selected.


    thanks in advance
  10. #10
    Please wrap the code in [CODE] tags instead of making it bold.
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: Feb 15, 2011, 5:38 AM
  2. [CLOSED] TreeNode's selected status
    By pumpkin in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Aug 03, 2009, 5:47 AM
  3. How to get NodeID of selected TreeNode?
    By dbassett74 in forum 1.x Help
    Replies: 9
    Last Post: May 26, 2009, 4:42 PM
  4. How to get selected TreeNode in JavaScript?
    By dbassett74 in forum 1.x Help
    Replies: 1
    Last Post: May 26, 2009, 1:34 PM
  5. Get full path of selected TreeNode?
    By dbassett74 in forum 1.x Help
    Replies: 2
    Last Post: May 18, 2009, 12:40 PM

Posting Permissions