tags:

views:

255

answers:

2

Hi

I am trying to dynamically (i.e. via code) bind a directory to a asp.net Treeview control and once the data is bound and displayed to the user i want to get a list of nodes the select.

I have got the binding and displaying of checkboxes to work fine , but when i query the Treeview1.CheckedNodes it always returns 0. If i do not bind dynamically but created the nodes by hand then it is able to get the selected nodes.

Thanks

+1  A: 

My guess is ... since you're dynamically building the whole thing from scratch every page load you're losing the selection.

You need to somehow store info about which checkboxes are checked before the post back (in Viewstate or Session or whatever depending on your needs) and then re-apply those selection to your tree after rebuilding it (on page load or preload if you store it in Viewstate).

JohnIdol
Yeah i forgot the if(!Page.IsPostBack) , i feel like such a noob :(
RC1140
it happens to the best of us :)
JohnIdol
A: 

i think you can using foreach to cycle the treeview.

like this:

public static void GetCheckedNode(TreeNodeCollection tnc) { foreach(TreeNode node in tnc) { if(node.Checked)    { MessageBox.Show(node.Text); }
   GetCheckedNode(node.Nodes); }

}

hope help you!

http://wind-flowers.net/