Originally Posted by
gmpd123
Thanks very much .
I also want to know if it's possible to get it from code behind. In the *.aspx.cs files, how can i get selected node and parent node of TreePanel
You can use the SelectedNodes collection. The example is below.
Though it doesn't allow to get a parent node. If you need that you should send this info via ExtraParams of DirectEvent.
Originally Posted by
gmpd123
dynamic add a node to a TreePanel from code behind?
Please see the example.
Example
<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
protected void GetSelectedNode(object sender, DirectEventArgs e)
{
TreeSelectionModel sm = this.TreePanel1.GetSelectionModel() as TreeSelectionModel;
string msg = "no selection";
if (sm.SelectedNodes != null)
{
SubmittedNode node = sm.SelectedNodes[0];
msg = node.Text;
}
X.Msg.Alert("GetSelectedNode", msg).Show();
}
protected void AddNode(object sender, DirectEventArgs e)
{
Node node = new Node()
{
Text = "NEW NODE",
Leaf = true
};
this.TreePanel1.GetNodeById("Root").AppendChild(node);
}
</script>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:TreePanel ID="TreePanel1" runat="server" AutoHeight="true">
<Root>
<ext:Node NodeID="Root" Text="Root (level 0)" Expanded="true">
<Children>
<ext:Node Text="Node1 (level 1)" Expanded="true">
<Children>
<ext:Node Text="Node1 (level 2)" Expanded="true">
<Children>
<ext:Node Text="Node1 (level 3)" Leaf="true" />
<ext:Node Text="Node2 (level 3)" Leaf="true" />
</Children>
</ext:Node>
</Children>
</ext:Node>
<ext:Node Text="Node2 (level 1)" Expanded="true">
<Children>
<ext:Node Text="Node1 (level 2)" Expanded="true">
<Children>
<ext:Node Text="Node1 (level 3)" Leaf="true" />
<ext:Node Text="Node2 (level 3)" Leaf="true" />
</Children>
</ext:Node>
</Children>
</ext:Node>
</Children>
</ext:Node>
</Root>
<SelectionModel>
<ext:TreeSelectionModel runat="server" />
</SelectionModel>
</ext:TreePanel>
<ext:Button runat="server" Text="Get Selected Node" OnDirectClick="GetSelectedNode" />
<ext:Button runat="server" Text="Add node" OnDirectClick="AddNode" />
</form>
</body>
</html>