PDA

View Full Version : treepanel in CodeBehind on button click ?



caoit
Apr 12, 2011, 1:32 PM
<ext:Button runat="server" ID = "btnLoad" Text="开始菜单">
<DirectEvents>
<Click OnEvent="btnLoad_Click"></Click>
</DirectEvents>
</ext:Button>
<asp:PlaceHolder ID="PlaceHolder1" runat="server" />

protected void btnLoad_Click(object sender, DirectEventArgs e)
{
Ext.Net.TreePanel tree = new Ext.Net.TreePanel();
tree.ID = "TreePanel1";
tree.Width = Unit.Pixel(300);
tree.Height = Unit.Pixel(450);
tree.Icon = Icon.BookOpen;
tree.Title = "Catalog";
tree.AutoScroll = true;
this.PlaceHolder1.Controls.Add(tree);
Ext.Net.Button btnExpand = new Ext.Net.Button();
btnExpand.Text = "Expand All";
btnExpand.Listeners.Click.Handler = tree.ClientID + ".expandAll();";

Ext.Net.Button btnCollapse = new Ext.Net.Button();
btnCollapse.Text = "Collapse All";
btnCollapse.Listeners.Click.Handler = tree.ClientID + ".collapseAll();";

Toolbar toolBar = new Toolbar();
toolBar.ID = "Toolbar1";
toolBar.Items.Add(btnExpand);
toolBar.Items.Add(btnCollapse);
tree.TopBar.Add(toolBar);

StatusBar statusBar = new StatusBar();
statusBar.AutoClear = 1000;
tree.BottomBar.Add(statusBar);

tree.Listeners.Click.Handler = statusBar.ClientID + ".setStatus({text: 'Node Selected: <b>' + node.text + '</b>', clear: true});";
tree.Listeners.ExpandNode.Handler = statusBar.ClientID + ".setStatus({text: 'Node Expanded: <b>' + node.text + '</b>', clear: true});";
tree.Listeners.ExpandNode.Delay = 30;
tree.Listeners.CollapseNode.Handler = statusBar.ClientID + ".setStatus({text: 'Node Collapsed: <b>' + node.text + '</b>', clear: true});";

Ext.Net.TreeNode root = new Ext.Net.TreeNode("Composers");
root.Expanded = true;
tree.Root.Add(root);
}


why treepanel no load?

Daniil
Apr 13, 2011, 1:03 PM
Hi,

I see where you create the tree, but can't see where you render it.

Please use .AddTo() to render.

tree.AddTo(someContainer);