一个IEWebControl TreeView右键菜单的例子,实现了添加、修改和删除功能,复制即可运行
更多TreeView的客户端操作参见
http://www.csdn.net/Develop/read_article.asp?id=22100

<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<HTML>
 <HEAD>
  <title>TreeView控件右键菜单</title>
  <style>
  <!--
   .skin
   {
   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>
 </HEAD>
 <body onclick="hideMenu()">
  <form ;
   var node = null;

   function hideMenu()
   {
    popupMenu.style.visibility = "hidden";
   }

   function highlighItem()
   {
    if (event.srcElement.className == "menuitems")
    {
     event.srcElement.style.backgroundColor = "highlight";
     event.srcElement.style.color = "white";
    }
   }

   function lowlightItem()
   {
    if (event.srcElement.className == "menuitems")
    {
     event.srcElement.style.backgroundColor = "";
     event.srcElement.style.color = "black";
     window.status = "";
    }
   }

   function clickItem()
   {    
    if (event.srcElement.className == "menuitems")
    {
     if(event.srcElement.getAttribute("func") == "add" && node != null)
     {
      var newNode=TreeView1.createTreeNode();
      newNode.setAttribute("Text","new Node");
      node.add(newNode);
     }
     else if (event.srcElement.getAttribute("func") == "delete" && node != null)
     {
      node.remove();
     }
     else if (event.srcElement.getAttribute("func") == "modify" && node != null)
     {
      node.setAttribute("Text","hgknight");
     }
    }
   }
   
   function TreeView1.oncontextmenu() 
   {
    var nodeindex = event.treeNodeIndex;
    if (typeof(nodeindex) == "undefined")
    {
     node = null;
     return;
    }
    
    node = TreeView1.getTreeNode(nodeindex);
    
    var rightedge = document.body.clientWidth-event.clientX;
    var bottomedge = document.body.clientHeight-event.clientY;
    if (rightedge <popupMenu.offsetWidth)
    {
     popupMenu.style.left = document.body.scrollLeft + event.clientX - popupMenu.offsetWidth;
    }
    else
    {
     popupMenu.style.left = document.body.scrollLeft + event.clientX;
    }
    if (bottomedge <popupMenu.offsetHeight)
    {
     popupMenu.style.top = document.body.scrollTop + event.clientY - popupMenu.offsetHeight;
    }
    else
    {
     popupMenu.style.top = document.body.scrollTop + event.clientY;
    }
    popupMenu.style.visibility = "visible";
    return false;
   } 
   
  </script>
 </body>
</HTML>

相关文章:

  • 2021-11-18
  • 2022-03-12
  • 2021-06-29
  • 2021-05-25
  • 2022-01-05
  • 2021-10-29
  • 2021-12-25
猜你喜欢
  • 2021-10-27
  • 2022-12-23
  • 2022-01-06
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案