I have a treeview that shows nodes according to a users role. if the user is not in the correct role I set visible = false on the node they should not see. However if a node has several children and all children are set to visible = false, the actual rendered HTML still includes an empty <UL> where they would have been. This causes a gap in the display.
I have come up with a workaround for anyone experiencing the same problem. You need to hook the treeview pre render as follows;
| protected void RadTreeView1_PreRender(object sender, EventArgs e) |
| { |
| // Note that although we set nodes that should not be displayed to visible = false |
| // Telerik still displays the <UL> for an empty section, we have to actually remove the nodes |
| // from the collection in order to display correctly. |
| // We use GetAllNodes for this as it returns every node in the tree and we count backwards |
| // so as not to upset the collection when items are removed. |
| for (int i = ((RadTreeView)sender).GetAllNodes().Count - 1; i >= 0 ; i--) |
| { |
| if (((RadTreeView)sender).GetAllNodes()[i].Visible == false) |
| { |
| ((RadTreeView)sender).GetAllNodes()[i].Remove(); |
| } |
| } |
| } |
This removes the nodes from the collection and displays correctly.
Darren