c# - ASP.NET TreeView + AJAX -
i have treeview i'm using display directory structure. trying cut down load times loading sub nodes on node expansion. there way this?
below code i'm using populate treeview:
protected void page_load(object sender, eventargs e) { buildtree(request.querystring["path"]); } private void buildtree(string dirpath) { //get root directory system.io.directoryinfo rootdir = new system.io.directoryinfo(dirpath); //create , add together root node tree view treenode rootnode = new treenode(rootdir.name, rootdir.fullname); treeview1.nodes.add(rootnode); //begin recursively traversing directory construction traversetree(rootdir, rootnode); } private void traversetree(system.io.directoryinfo currentdir, treenode currentnode) { //loop through each sub-directory in current 1 foreach (system.io.directoryinfo dir in currentdir.getdirectories()) { //create node , add together tree view treenode node = new treenode(dir.name, dir.fullname); currentnode.childnodes.add(node); //recursively phone call same method go downwards next level of tree traversetree(dir, node); } foreach (system.io.fileinfo file in currentdir.getfiles()) { treenode node = new treenode(file.name, file.fullname); currentnode.childnodes.add(node); } }
for loading nodes on demand, meaning children of node loaded when parent node expanded. next steps:
1 - set treeview.expanddepth 0. eliminates expansion of added treenode
objects in treeview
, shows expansion symbol [+] next each treenode
has treenode.populateondemand
property set true.
2- set treenode.populateondemand true each branch treenode
. when treenode.childnodes
collection empty, expansion symbol [+] showed next treenode
objects has treenode.populateondemand
property set true.
3- handle treeview.treenodepopulate event poulate branch nodes on expansion. event fired when treenode
- treenode.populateondemand
set true - has been expanded right before treeview.treenodeexpanded
event gets fired.
source: asp.net treeview , loading info on demand
c# asp.net ajax
No comments:
Post a Comment