在asp.net中隐藏树视图节点 [英] Hide tree view node in asp.net

查看:87
本文介绍了在asp.net中隐藏树视图节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello ALL,

我需要在asp.net中隐藏一个节点,具体取决于不同的用户。

我试过将文本设为null,这种方式适用于子节点但是对于父节点,如果文本被赋予为null,则文本不会显示在页面上,但是在树视图中的+符号可见。



so我需要一些方法来完全隐藏父节点或者我需要隐藏那个+符号..



任何人都可以帮助!!!

Hello ALL,
I need to hide a node in asp.net depending on different user.
I have tried giving text as null, this way will work for child node but for parent node if text is given as null, text wont show up on page, but ''+'' sign in tree view is visible.

so I need some way to hide the parent node fully or I need to hide that + sign..

can anyone help!!!

推荐答案

salah,



您可以使用以下代码隐藏相应用户的节点,只需传递您想要的节点索引根据不同的用户隐藏。

Hi salah,

You can use below code to hide node for the respective user, just pass the Index of node which u want to hide depending on different user.
TreeView.Nodes.RemoveAt(NodeIndex)


试试这个:

Try this:
protected void Page_Load(object sender, EventArgs e)
{
  RemoveNodeRecurrently(TreeView1.Nodes, "YourTreeNodeText");
}

private void RemoveNodeRecurrently(TreeNodeCollection childNodeCollection, string text)
{
  foreach (TreeNode childNode in childNodeCollection)
  {
    if (childNode.ChildNodes.Count > 0)
      RemoveNodeRecurrently(childNode.ChildNodes, text);

    if (childNode.Text == text)
    {
      TreeNode parentNode = childNode.Parent;
      parentNode.ChildNodes.Remove(childNode);
      break;
    }
  }
}



原始主题 [ ^ ]。





--Amit


Original Thread[^].


--Amit


这篇关于在asp.net中隐藏树视图节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆