Treeview with node hover

Source: Internet
Author: User

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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.