标记:
<asp:TreeView ID="TreeView2" runat="server" ImageSet="Inbox" Width="200px">
<ParentNodeStyle Font-Bold="True" />
<HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
<SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px" VerticalPadding="0px"
ForeColor="#5555DD" />
<Nodes>
<asp:TreeNode Text="New Request" Value="Home" NavigateUrl="~/NewRequest.aspx" ToolTip="New Request">
</asp:TreeNode>
<asp:TreeNode NavigateUrl="~/MyCertificates.aspx" Text="My Certificates" Value="Help"
ToolTip="My Certificates"></asp:TreeNode>
<asp:TreeNode NavigateUrl="~/MyRequest.aspx" Text="My Requests" Value="Help"
ToolTip="My Request"></asp:TreeNode>
<asp:TreeNode NavigateUrl="~/AdminRights.aspx" Text="Admin" Value="admin only"
ToolTip="Admin"></asp:TreeNode>
<asp:TreeNode NavigateUrl="~/Reneval.aspx""
Text="Download Root Certificate" Value="RootCertificate" ToolTip="Download Root Certificate">
</asp:TreeNode>
</Nodes>
<NodeStyle Font-Names="Calibri" Font-Size="8pt" ForeColor="DarkGray" HorizontalPadding="5px"
NodeSpacing="0px" VerticalPadding="0px" />
<LeafNodeStyle ForeColor="Black" />
</asp:TreeView>
我正在尝试删除某个条件的节点管理员,但它没有被删除。
private void ShowAdminOptions()
{
TreeNode tnObj = TreeView2.FindNode("Admin");
if (tnObj != null)
{
TreeView2.Nodes.Remove(tnObj);
}
}
tnObj
始终为空。
答案 0 :(得分:0)
这一行错了:
<asp:TreeNode NavigateUrl="~/AdminRights.aspx" Text="Admin" Value="admin only"
ToolTip="Admin"></asp:TreeNode>
值应为“管理员”,而不是“仅限管理员”。
TreeView.FindNode Method: Retrieves the TreeNode object in the TreeView control at the specified value path.