xhchc

          危波帆墻,笑談只在桃花上;與誰共尚,風(fēng)吹萬里浪; 相依相偎,不做黃泉想;莫惆悵,碧波潮生,一蕭自狂放……

           

          IEWebControl TreeView右鍵菜單實例

           

          一個IEWebControl TreeView右鍵菜單的例子,實現(xiàn)了添加、修改和刪除功能,復(fù)制即可運行
          更多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 id="TreeView" method="post" runat="server">
             <iewc:TreeView id="TreeView1" runat="server" ExpandLevel="3" HoverStyle="color:blue;background:#ffff00;">
              <iewc:TreeNode Text="Node0" Expanded="True">
               <iewc:TreeNode Text="Node3">
                <iewc:TreeNode Text="Node5"></iewc:TreeNode>
                <iewc:TreeNode Text="Node6"></iewc:TreeNode>
               </iewc:TreeNode>
               <iewc:TreeNode Text="Node4"></iewc:TreeNode>
              </iewc:TreeNode>
              <iewc:TreeNode Text="Node1" Expanded="True">
               <iewc:TreeNode Text="Node7">
                <iewc:TreeNode Text="Node8"></iewc:TreeNode>
               </iewc:TreeNode>
              </iewc:TreeNode>
              <iewc:TreeNode Text="Node2" Expanded="True">
               <iewc:TreeNode Text="Node9"></iewc:TreeNode>
               <iewc:TreeNode Text="Node10">
                <iewc:TreeNode Text="Node11"></iewc:TreeNode>
                <iewc:TreeNode Text="Node12"></iewc:TreeNode>
               </iewc:TreeNode>
              </iewc:TreeNode>
             </iewc:TreeView>
             <div id="popupMenu" class="skin" onMouseover="highlighItem()" onMouseout="lowlightItem()" onClick="clickItem()">
              <div class="menuitems" func="add">添加</div>
              <hr>
              <div class="menuitems" func="delete">刪除</div>
              <div class="menuitems" func="modify">修改</div>
             </div>
            </form>
            <script language="javascript">
             var menuskin = "skin";
             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>

          posted on 2008-07-10 17:47 chu 閱讀(211) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           

          導(dǎo)航

          統(tǒng)計

          常用鏈接

          留言簿(2)

          隨筆檔案

          我的鏈接

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 赣州市| 女性| 庄河市| 阿勒泰市| 黄龙县| 班玛县| 阿拉善右旗| 红桥区| 天水市| 太白县| 平远县| 新干县| 女性| 舞阳县| 大连市| 沙坪坝区| 宿迁市| 紫云| 滨海县| 科尔| 沾化县| 五家渠市| 华坪县| 芷江| 滨海县| 上栗县| 象州县| 德令哈市| 新泰市| 仲巴县| 文山县| 宣汉县| 宝兴县| 靖西县| 浏阳市| 竹山县| 温州市| 清河县| 贡觉县| 常德市| 鸡东县|