Asp.net tree view - Event not fired when Click on the same node
Is there any way to raise the SelectedNodeChanged event on selecting the node twice. I cant use the code "treeview.SelectedNode.Selected = false" as i have to show the 开发者_如何学Goselected node of the tree but at the same time, i want some event so that i can capture the click on node. Is there any way to do so ?
Thanks in advance
What you could do is put the code in another event like the prerender and you can determine if the selection has changed by having a boolean class variable, blnIsChanged for example. This value has the default value of false is only set to true in the SelectedNodeChanged event so you can have an if statement in the prerender (or any event that would fire after the SelectedNodeChanged event) that can execute your code if blnIsChanged = false and do nothing if it = true.
Example:
Partial Class YourPageWithaAtreeView
Inherits System.Web.UI.Page
Dim _blnSelectionChanged as Boolean = false
Protected Sub MyTree_SelectedNodeChanged(byval sender as object, byval e as eventargs) handles MyTree.SelectedNodeChanged
_blnSelectionChanged = true //The selection changed
End Sub
Protected Sub MyTree_PreRender(byval sender as object, byval e as eventargs) handles MyTree.PreRender
if _blnSelectionChanged = false Then
//Because the boolean is not true that means that
//the selected node didn't change
//insert the code you want to execute when the user
//clicks the already selected node
end if
End Sub
Yes, it's really annoying that there's no OnNodeClick() event for the standard TreeView control.
I ended up using Telerik's version (the 'RadTreeView') which does support this event.
The other way is to write your own handler in a round-about way as described here: http://www.programmersheaven.com/mb/csharp/341363/341363/event-handling-treeview/
精彩评论