2013-08-19 42 views

回答

0

你的ASP.NET的TreeView:

<asp:TreeView ID="tvMain" runat="server" ExpandDepth="10"  OnTreeNodeExpanded="tvMain_TreeNodeExpanded" OnTreeNodeCollapsed="tvMain_TreeNodeCollapsed"> 
    <RootNodeStyle Font-Bold="true" /> 
    <Nodes> 
     <asp:TreeNode Text="Root" Value="Root"> 
      <asp:TreeNode Text="Link2" Value="Link1"></asp:TreeNode> 
      <asp:TreeNode Text="Link2" Value="Link2"></asp:TreeNode> 
     </asp:TreeNode> 

    </Nodes> 
</asp:TreeView> 

後面的代碼:

Protected Sub tvMain_TreeNodeCollapsed(sender As Object, e As System.Web.UI.WebControls.TreeNodeEventArgs) 
    If Page.IsPostBack Then 
     If e.Node.Value.Equals("Root") Then 
      'Do your stuff' 
     End If 
    End If 
End Sub 


Protected Sub tvMain_TreeNodeExpanded(sender As Object, e As System.Web.UI.WebControls.TreeNodeEventArgs) 
    If Page.IsPostBack Then 
     If e.Node.Value.Equals("Root") Then 
      'Do your stuff' 
     End If 
    End If 
End Sub 

訣竅是處理OnTreeNodeCollapsed事件和OnTreeNodeExpanded事件。接下來,您爲您的根節點選擇一個值 - 即第一個和單個子節點。您將節點添加到根節點,並確保它們具有與根節點不同的值。

相關問題