Export (0) Print
Expand All

TreeView.ExpandAll Method

Note: This method is new in the .NET Framework version 2.0.

Opens every node in the tree.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public void ExpandAll ()
public void ExpandAll ()
public function ExpandAll ()

The ExpandAll method provides a convenient way to open every node in the tree.

The following code example demonstrates how to use the ExpandAll method to expand all the nodes in the TreeView control at the same time.


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

<script runat="server">

  void Button_Command(Object sender, CommandEventArgs e)
  {

    switch(e.CommandName)
    {

      case "Expand":
        LinksTreeView.ExpandAll();
        break;
      case "Collapse":
        LinksTreeView.CollapseAll();
        break;
      default:
        // Do nothing.
        break;

    }

  }

</script>

<html>
  <body>
    <form runat="server">
    
      <h3>TreeView ExpandAll and CollapseAll Example</h3>
    
      <asp:TreeView id="LinksTreeView"
        Font-Name= "Arial"
        ForeColor="Blue"
        runat="server">
         
        <LevelStyles>
        
          <asp:TreeNodeStyle ChildNodesPadding="10" 
            Font-Bold="true" 
            Font-Size="12pt" 
            ForeColor="DarkGreen"/>
          <asp:TreeNodeStyle ChildNodesPadding="5" 
            Font-Bold="true" 
            Font-Size="10pt"/>
          <asp:TreeNodeStyle ChildNodesPadding="5" 
            Font-UnderLine="true" 
            Font-Size="10pt"/>
          <asp:TreeNodeStyle ChildNodesPadding="10" 
            Font-Size="8pt"/>
             
        </LevelStyles>
         
        <Nodes>
        
          <asp:TreeNode Text="Table of Contents"
            SelectAction="None">
             
            <asp:TreeNode Text="Chapter One">
            
              <asp:TreeNode Text="Section 1.0">
              
                <asp:TreeNode Text="Topic 1.0.1"/>
                <asp:TreeNode Text="Topic 1.0.2"/>
                <asp:TreeNode Text="Topic 1.0.3"/>
              
              </asp:TreeNode>
              
              <asp:TreeNode Text="Section 1.1">
              
                <asp:TreeNode Text="Topic 1.1.1"/>
                <asp:TreeNode Text="Topic 1.1.2"/>
                <asp:TreeNode Text="Topic 1.1.3"/>
                <asp:TreeNode Text="Topic 1.1.4"/>
              
              </asp:TreeNode>
            
            </asp:TreeNode>
            
            <asp:TreeNode Text="Chapter Two">
            
              <asp:TreeNode Text="Section 2.0">
              
                <asp:TreeNode Text="Topic 2.0.1"/>
                <asp:TreeNode Text="Topic 2.0.2"/>
              
              </asp:TreeNode>
            
            </asp:TreeNode>
            
          </asp:TreeNode>
          <asp:TreeNode Text="Appendix A" />
          <asp:TreeNode Text="Appendix B" />
          <asp:TreeNode Text="Appendix C" />
        
        </Nodes>
        
      </asp:TreeView>
      
      <hr>
      
      <asp:Button id="ExpandButton" 
        CommandName="Expand"
        Text="Expand All Nodes"
        OnCommand="Button_Command"
        runat="server"/>
         
      &nbsp;
      
      <asp:Button id="CollapseButton" 
        CommandName="Collapse"
        Text="Collapse All Nodes"
        OnCommand="Button_Command"
        runat="server"/>

    </form>
  </body>
</html>


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft