Treeview with mouse hover
Wen/min zhongchengThis example is composed of unpublished [Asp. net 3.5 images] is extracted to show a piece of text when the mouse moves to an item during Treeview. So what's the problem? The difficulty lies in the fact that Treeview itself does not provide such functionality, that is, Treeview does not support this approach from the design architecture. In fact, it is not difficult to achieve this effect. We all know that Treeview produces a group of TR and td html scripts, if we can get the TR and td html id of each node, then we can pass through JavaScript to attath hover event to the HTML element, the final result is that when the mouse moves to the node, a javascript program is written, that is, the hover! Then, the question is how to obtain this html id. The following code can be used to call the Treeview private function with reflection.
Protected void page_prerendercomplete (Object sender, eventargs e ){Propertyinfo Pi = typeof (treenode). getproperty ("Index ",Bindingflags. Instance | bindingflags. nonpublic );Foreach (treenode node in treeview1.nodes){Object Index = pi. getvalue (node, null );Clientscript. registerstartupscript (GetType (), treeview1.clientid + "_" + index. tostring () + "_ hook", String. format ("hookevent (document. getelementbyid ('{0}'); ", treeview1.clientid +" T "+ index. tostring (), true );}} |
Through the treenode private index adequacy, you can obtain the clientid of the treenode, which is the clientid of the treenode with the clientid of the Treeview. With this ID, you can attach the event. The complete program example is as follows:
. Aspx |
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %> <! Doctype HTML public "-// W3C // dtd xhtml 1.1 // en" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml"> |
. Aspx. CS |
Using system; using system. data; using system. configuration; using system. web; using system. web. security; using system. web. ui; using system. web. UI. webcontrols; using system. web. UI. webcontrols. webparts; using system. web. UI. htmlcontrols; using system. reflection; public partial class _ default: system. web. UI. page {protected void page_load (Object sender, eventargs e) {} protected void page_prerendercomplete (Object sender, eventargs e) {propertyinfo Pi = typeof (treenode ). getproperty ("Index", bindingflags. instance | bindingflags. nonpublic); foreach (treenode node in treeview1.nodes) {object index = pi. getvalue (node, null); clientscript. registerstartupscript (GetType (), treeview1.clientid + "_" + index. tostring () + "_ hook", String. format ("hookevent (document. getelementbyid ('{0}'); ", treeview1.clientid +" T "+ index. tostring (), true );}}} |
Please note! I have used the attachevent of IE compute to upload events. If you want to operate normally on Firefox, use addeventlister instead.