Right-click the Treeview menu in Asp.net 2.0

Source: Internet
Author: User

Turn: http://hi.baidu.com/wqeast/blog/item/c085db2a5907cc9b033bf6b9.html

A few ASP. NET 2.0 Treeview coders were asking for a how to have context menus-per node-on the Treeview control. well I spent a small amount of time on this and wanted to post one solution. A few caveats:

A. ie specific
B. I never optimized the JavaScript to use parameters

Hope this helps soeone achieve what they need. If you find a better solution please feel free to let me know!

 

 

<% @ Page Language = "C #" %>

<HTML>
<Head>
<Style>
<! --
. Skin1 {
Cursor: default;
Font: menutext;
Position: absolute;
Text-align: left;
Font-family: Arial, Helvetica, sans-serif;
Font-size: 10pt;
Width: 120px;
Background-color: menu;
Border: 1 solid buttonface;
Visibility: hidden;
Border: 2 outset buttonhighlight;
}
. Menuitems {
Padding-left: 15px;
Padding-Right: 10px;
}
-->
</Style>

<SCRIPT type = "text/JavaScript">

<! -- Begin
VaR menuskin = "skin1 ";
VaR display_url = 1; // show URLs in status bar?
Function showmenuie5 (){
If (event. srcelement. type! = Undefined)
{
VaR S = event. srcelement. ID;
VaR ind = S. Replace ("treeview1t ","");
S = S. Replace ("treeview1t", "treeview1n ");

Document. getelementbyid ('one'). url = event. srcelement. href;
Document. getelementbyid ('one'). innertext = "select ";
VaR CH = Document. getelementbyid (s );
If (Ch! = NULL ){
Document. getelementbyid ('two '). url = "javascript: treeview_togglenode (treeview1_data," + ind + "," + S + ",'', "+ S +" nodes )";
Document. getelementbyid ('two'). innertext = "Expand // collapse ";
}
Else
Document. getelementbyid ('two'). outerhtml = "<Div id = two class = menuitems url =''> </div>"

VaR rightedge = Document. Body. clientWidth-event.clientX;
VaR BottomEdge = Document. Body. The clientHeight-event.clientY;
If (rightedge <ie5menu. offsetwidth)
Ie5menu. style. Left = Document. Body. scrollleft + event. clientx-ie5menu. offsetwidth;
Else
Ie5menu. style. Left = Document. Body. scrollleft + event. clientx;
If (BottomEdge <ie5menu. offsetheight)
Ie5menu. style. Top = Document. Body. scrolltop + event. clienty-ie5menu. offsetheight;
Else
Ie5menu. style. Top = Document. Body. scrolltop + event. clienty;
Ie5menu. style. Visibility = "visible ";
}
Else
{
Ie5menu. style. Visibility = "hidden ";
}
Return false;
}
Function hidemenuie5 (){
Ie5menu. style. Visibility = "hidden ";
}
Function highlightie5 (){
If (event. srcelement. classname = "menuitems "){
Event. srcelement. style. backgroundcolor = "highlight ";
Event. srcelement. style. color = "white ";
If (display_url)
Window. Status = event. srcelement. url;
}
}
Function lowlightie5 (){
If (event. srcelement. classname = "menuitems "){
Event. srcelement. style. backgroundcolor = "";
Event. srcelement. style. color = "black ";
Window. Status = "";
}
}
Function jumptoie5 (){
If (event. srcelement. classname = "menuitems "){
If (event. srcelement. getattribute ("target ")! = NULL)
Window. Open (event. srcelement. url, event. srcelement. getattribute ("target "));
Else
Window. Location = event. srcelement. url;
}
}
// End -->
</SCRIPT>

</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div id = "ie5menu" class = "skin0" onmouseover = "highlightie5 ()" onmouseout = "lowlightie5 ()"
Onclick = "jumptoie5 ();">
<Div id = "one" class = "menuitems" url = "">
</Div>
<Div id = "two" class = "menuitems" url = "">
</Div>
</Div>
<Asp: Treeview id = "treeview1" runat = "server">
<Nodes>
<Asp: treenode text = "A" value = "A">
<Asp: treenode text = "B" value = "B">
<Asp: treenode text = "C" value = "C"> </ASP: treenode>
</ASP: treenode>
</ASP: treenode>
<Asp: treenode text = "cc" value = "cc">
<Asp: treenode text = "CCC" value = "CCC">
<Asp: treenode text = "CCCC" value = "CCCC"> </ASP: treenode>
</ASP: treenode>
</ASP: treenode>
</Nodes>
<Selectednodestyle backcolor = "# c00000"/>
</ASP: Treeview>
</Form>

<SCRIPT type = "text/JavaScript">
If (document. All ){
Ie5menu. classname = menuskin;
Document. getelementbyid ('treeview1'). oncontextmenu = showmenuie5;
Document. Body. onclick = hidemenuie5;
}
</SCRIPT>
</Body>
</Html>

 

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.