다음을 통해 공유


TreeView.FindNode(String) 메서드

정의

지정된 값 경로에서 TreeNode 컨트롤의 TreeView 개체를 검색합니다.

public:
 System::Web::UI::WebControls::TreeNode ^ FindNode(System::String ^ valuePath);
public System.Web.UI.WebControls.TreeNode FindNode (string valuePath);
member this.FindNode : string -> System.Web.UI.WebControls.TreeNode
Public Function FindNode (valuePath As String) As TreeNode

매개 변수

valuePath
String

노드의 값 경로입니다.

반환

지정된 값 경로의 TreeNode입니다.

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 FindNode 에서 노드를 검색 하는 메서드는 TreeView 컨트롤입니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void Button_Click(Object sender, EventArgs e)
  {

    // Find the node specified by the user.
    TreeNode node = LinksTreeView.FindNode(Server.HtmlEncode(ValuePathText.Text));

    if (node != null)
    {
      // Indicate that the node was found.
      Message.Text = "The specified node (" + node.ValuePath + ") was found.";
    }
    else
    {
      // Indicate that the node is not in the TreeView control.
      Message.Text = "The specified node (" + ValuePathText.Text + ") is not in this TreeView control.";
    }

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head runat="server">
    <title>TreeView FindNode Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView FindNode Example</h3>
    
      <asp:TreeView id="LinksTreeView"
        PathSeparator="/"
        Font-Names= "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" Value="Chapter One">
            
              <asp:TreeNode Text="Section 1.0" Value="Section 1.0">
              
                <asp:TreeNode Text="Topic 1.0.1" Value="Topic 1.0.1"/>
                <asp:TreeNode Text="Topic 1.0.2" Value="Topic 1.0.2"/>
                <asp:TreeNode Text="Topic 1.0.3" Value="Topic 1.0.3"/>
              
              </asp:TreeNode>
              
              <asp:TreeNode Text="Section 1.1">
              
                <asp:TreeNode Text="Topic 1.1.1" Value="Topic 1.1.1"/>
                <asp:TreeNode Text="Topic 1.1.2" Value="Topic 1.1.2"/>
                <asp:TreeNode Text="Topic 1.1.3" Value="Topic 1.1.3"/>
                <asp:TreeNode Text="Topic 1.1.4" Value="Topic 1.1.4"/>
              
              </asp:TreeNode>
            
            </asp:TreeNode>
            
            <asp:TreeNode Text="Chapter Two" Value="Chapter Two">
            
              <asp:TreeNode Text="Section 2.0" Value="Section 2.0">
              
                <asp:TreeNode Text="Topic 2.0.1" Value="Topic 2.0.1"/>
                <asp:TreeNode Text="Topic 2.0.2" Value="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/>
      
      <br/><br/>
      
      Enter the value path of the node to locate. <br/>
      Use a forward slash (/) to delimit each node value.<br/>
      <asp:TextBox id="ValuePathText" 
        Text="Table of Contents/Chapter One/Section 1.0"
        Width="50%" 
        runat="server"/>
         
      <br/><br/>
      
      <asp:Button id="Submit"
        Text="Find Node"
        OnClick="Button_Click"  
        runat="server"/>
      
      <br/><br/>
      
      <asp:Label id="Message" runat="server"/>

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

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)

    ' Find the node specified by the user.
    Dim node As TreeNode = LinksTreeView.FindNode(Server.HtmlEncode(ValuePathText.Text))

    If Not node Is Nothing Then
   
      ' Indicate that the node was found.
      Message.Text = "The specified node (" & node.ValuePath & ") was found."

    Else

      ' Indicate that the node is not in the TreeView control.
      Message.Text = "The specified node (" & ValuePathText.Text & ") is not in this TreeView control."

    End If

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head runat="server">
    <title>TreeView FindNode Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView FindNode Example</h3>
    
      <asp:TreeView id="LinksTreeView"
        PathSeparator="/"
        Font-Names= "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" Value="Chapter One">
            
              <asp:TreeNode Text="Section 1.0" Value="Section 1.0">
              
                <asp:TreeNode Text="Topic 1.0.1" Value="Topic 1.0.1"/>
                <asp:TreeNode Text="Topic 1.0.2" Value="Topic 1.0.2"/>
                <asp:TreeNode Text="Topic 1.0.3" Value="Topic 1.0.3"/>
              
              </asp:TreeNode>
              
              <asp:TreeNode Text="Section 1.1">
              
                <asp:TreeNode Text="Topic 1.1.1" Value="Topic 1.1.1"/>
                <asp:TreeNode Text="Topic 1.1.2" Value="Topic 1.1.2"/>
                <asp:TreeNode Text="Topic 1.1.3" Value="Topic 1.1.3"/>
                <asp:TreeNode Text="Topic 1.1.4" Value="Topic 1.1.4"/>
              
              </asp:TreeNode>
            
            </asp:TreeNode>
            
            <asp:TreeNode Text="Chapter Two" Value="Chapter Two">
            
              <asp:TreeNode Text="Section 2.0" Value="Section 2.0">
              
                <asp:TreeNode Text="Topic 2.0.1" Value="Topic 2.0.1"/>
                <asp:TreeNode Text="Topic 2.0.2" Value="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/>
      
      <br/><br/>
      
      Enter the value path of the node to locate. <br/>
      Use a forward slash (/) to delimit each node value.<br/>
      <asp:TextBox id="ValuePathText" 
        Text="Table of Contents/Chapter One/Section 1.0"
        Width="50%" 
        runat="server"/>
         
      <br/><br/>
      
      <asp:Button id="Submit"
        Text="Find Node"
        OnClick="Button_Click"  
        runat="server"/>
      
      <br/><br/>
      
      <asp:Label id="Message" runat="server"/>

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

설명

사용 하 여는 FindNode 에서 노드를 가져오기 위한 메서드를 TreeView 지정한 값 경로 있는 컨트롤입니다. 값 경로 루트 노드에서 현재 노드까지의 경로 구성 하는 노드 값의 구분 기호로 구분 된 목록을 포함 합니다. 각 노드에 해당 값 경로에 저장 된 ValuePath 속성입니다. PathSeparator 속성 노드 값을 구분 하는 데 사용 되는 구분 기호 문자를 지정 합니다.

적용 대상

추가 정보