Asp.net 树视图 - 单击同一节点时不会触发事件
有没有办法在选择节点两次时引发 SelectedNodeChanged 事件。我无法使用代码“treeview.SelectedNode.Selected = false”,因为我必须显示树的选定节点,但同时,我想要一些事件,以便我可以捕获节点上的点击。有什么办法可以做到吗?
提前致谢
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 selected 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以做的是将代码放在另一个事件中,例如预渲染,您可以通过布尔类变量(例如 blnIsChanged)来确定选择是否已更改。该值的默认值 false 仅在 SelectedNodeChanged 事件中设置为 true,因此您可以在预渲染(或在 SelectedNodeChanged 事件之后触发的任何事件)中使用 if 语句,如果 blnIsChanged = false 并执行该操作,则可以执行您的代码如果它 = true 则什么也没有。
例子:
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:
是的,标准 TreeView 控件没有 OnNodeClick() 事件,这确实很烦人。
我最终使用了 Telerik 的版本(' RadTreeView') 确实支持此事件。
另一种方法是以迂回的方式编写您自己的处理程序,如下所述:
http://www.programmersheaven.com/mb/csharp/ 341363/341363/事件处理-treeview/
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/