|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Treeview control determining if node expanded or selectedI have a asp.net 2.0 treeview control which I populate nodes using the new client call back (populatenodeondemand = true). This works fine and my _TreeNodePopulate event handler handles the event fired when a node is expanded and populates the child nodes. However, I now need to use the treeview in a slightly different way. When expanding a node I want my existing code to populate child nodes on demand. But when a node is selected I want to call some other server side code. It seems that my _TreeNodePopulate event handler is called even when I select a node by clicking on the node text. Also the e.Node.Value does not refer to the node I select but the parent node in the treeview! I cannot seem to find a way to determine if the node has been expanded or selected in order to call the correct code. I have tried setting the SelectAction to various values and I also have tried checking the e.node.Selected property but it always returns false even when I have selected a node. Please can someone explain how I can determine if the node refered to in the event has been expanded ot selected. Thanks Lewis Holmes eNate Hi,
In the MSDN example for TreeNode.PopulateOnDemand() - the strategy is: Within the OnTreeNodePopulate handler 1. Create and set non-leaf nodes' PopulateOnDemand to true. 2. Set non-leaf nodes' SelectAction to Expand. 3. Create and set the leaf nodes' PopulateOnDemand to false 4. Set the leaf nodes' SelectAction to Select. http://msdn2.microsoft.com/en-US/library/system.web.ui.webcontrols.treenode.populateondemand(VS.80).aspx This is because for most situations it is *only* the leaf nodes that should raise the select event and this would neatly sidestep your problem. You can then handle the SelectNodeChanged event and process the leaf nodes that were selected. Hope that was clear. Hi Lewis,
As for the TreeView control's TreeNodes, for non-leaf child nodes, if you only want to expand them and populate new nodes, but do not want to do any processing when selecting them, you can follow the strategy mentioned in the msdn reference Caffiene has mentioned. If those non-leaf child nodes need both selecting and populating event, I think you need to set the their "SelectAction" to "Select". Thus, when we click on the node (the text), only "SelectedNodeChanged" event will be fired and for "populate" event, it will fire only when we click the "+" flag, and this will fire once for each node. Regards, Steven Cheng Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Adding controls to Pager row in GridView
Templated control not rendering Web User Controls ASP.NET 2.0 equivalent for e.Item.ItemIndex ? using placeholders stylesheet on ASP.NET 2.0 TreeView and Menu Control Change style of Edit-button in GridView? servercontrols (webcontrols, htmlcontrols) or html elements? Display data in asp:Calendar Gridview and colspan Scroll position in panel control |
|||||||||||||||||||||||