⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tvexample.aspx

📁 ddddddddddddd dddddddd ddddddddd sdddddddd sdddddddddd sddddddddd sddddddddddddddd sssssssssss sssss
💻 ASPX
字号:
<%@ Page language="c#" Codebehind="TVExample.aspx.cs" AutoEventWireup="false" Inherits="Mike.Elliott.Articles.TreeView.TVExample" %>
<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 

<html>
  <head>
    <title>Tree View Example</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
  </head>
  <body MS_POSITIONING="GridLayout">
  
  <script language="javascript">
    // Intercepts the index changed event on the client.
    //  
    function TVIndexChanged()
    {
      ChangeText( 'node changed' );
    }
    
    
    // Intercepts the collapsed event on the client.
    //    
    function TVNodeExpand()
    {
      ChangeText( 'onexpand' );
    }
    
    
    // Intercepts the collapsed event on the client.
    //
    function TVNodeCollapse()
    {
      ChangeText( 'oncollapse' );
    }
    
    
    // Intercepts the double-click event on the client.
    //    
    function TVDoubleClick()
    {
      ChangeText( 'dblclick' );
    }
    
    
    // Intercepts the right-click event on the client. The selected 
    // tree node is changed to the node over which the end user has 
    // right-clicked so that, that node's meta-data can be obtained.
    //
    function TVRightClick()
    {
      // Before changing the selected node, validate the node 
      // is valid.
      var tree = GetTreeHandle();
      var treenode;
      
      if ( null == tree || undefined == tree )
        return;
      
      // Get the selected node's 'NodeData'.
      treenode = tree.getTreeNode( event.treeNodeIndex );  
      
      if ( null == treenode || undefined == treenode )
        return;
        
      // Cause the tree node that was right-clicked on to become the 
      // selected node.  
      tree.selectedNodeIndex = event.treeNodeIndex;   
        
      ChangeText( 'oncontextmenu' );
    }
        
    
    // Simply changes the information in the display text boxes to 
    // demonstrate how to obtain meta-data from the selected node's 
    // NodeData property on the client.
    //
    function ChangeText( eventName )
    {
      var treeNode = GetSelectedNode();
          
      if ( null == treeNode || undefined == treeNode )
      {
        return;
      }     
          
      var nodeData = treeNode.getAttribute( 'nodeData' ).split( ';' );          
              
      var id = GetKeyValue( 'SomeId' );
      var name = GetKeyValue( 'Name' );
              
      // ChangeText( 'SomeId = ' + someId + '\tName: ' + name );
          
      document.getElementById( 'txtEvent' ).value = eventName;
      document.getElementById( 'txtId' ).value = id;
      document.getElementById( 'txtName' ).value = name;
    }
    
    
    // Gets the value of the searchKey from the NodeData of a TreeNode.
    //
    function GetKeyValue( searchKey )
    {   
      // Get a handle to the selected TreeNode.
      var treenode = GetSelectedNode();
        
      // Validate the node handle.
      if ( null == treenode || undefined == treenode )
        return null;
      
      // Get the node's NodeData property's value.
      var nodeDataAry = treenode.getAttribute( 'nodeData' );
      
      if ( null == nodeDataAry || undefined == nodeDataAry )
        return null;
        
      nodeDataAry = nodeDataAry.split( ';' );

      if ( null == nodeDataAry || undefined == nodeDataAry || 
          0 >= nodeDataAry.length )
        return null;
      
      var count = 0;
      var returnValue = null;
      
      while ( count < nodeDataAry.length )
      {
        var workingItem = nodeDataAry[ count ];
        
        if ( 0 >= workingItem.length )
        {
          count++;
          continue;
        }
        
        // Split the string into its key value pairs.
        var kv = workingItem.split( '=' );
        
        if ( 1 >= kv.length )
        {
          count++;
          continue;
        }
          
        var key = kv[ 0 ];
        var kValue = kv[ 1 ];
        
        if ( key != searchKey )
        {
          count++;
          continue;
        }
        
        returnValue = kValue;
        break;
      }       
      
      return returnValue;
    }
      
      
    // Gets a handle to the TreeView.
    //
    function GetTreeHandle()
    {
      var tree;
      var treeName = 'tvControl';
         
      // Get a handle to the TreeView.
      tree = document.getElementById( treeName );
      
      if ( null == tree || undefined == tree )
        return null;
        
      return tree;
    }     
    
    
    // Gets a handle to the TreeView's selected node.
    //
    function GetSelectedNode()
    {
      var tree = GetTreeHandle();
      var treeNode;
      
      if ( null == tree || undefined == tree )
        return null;
      
      treeNode = tree.getTreeNode( tree.selectedNodeIndex );  
      
      if ( null == treeNode || undefined == treeNode )
        return null;
      
      return treeNode;
    }   
  </script>  
    <form id="frmTVExample" method="post" runat="server">
      <table width="100%" align="center" border="0">
        <tr><td>
          <iewc:treeview id="tvControl" runat="server" 
            SystemImagesPath="/webctrl_client/1_0/treeimages/" 
            EnableViewState="False">
          </iewc:treeview>
        </td></tr>
        <tr><td><input type="text" id="txtId" name="txtId"</td></tr>
        <tr><td><input type="text" id="txtName" name="txtName"</td></tr>
        <tr><td><INPUT type="text" id="txtEvent" name="txtEvent"></td> </tr>
      </table>
    </form>
  
  </body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -