private string RenderNode(string prefix, int Level, TreeNode CurrentNode, bool IsLastNode) { if (OnNodeRender != null) { CurrentNode = OnNodeRender(IsLastNode, Level, CurrentNode); } Text = new LinkTag(); List <TreeNode> ChildList = Data.Where(c => c.ParentId == CurrentNode.Id).ToList(); bool HasChild = (ChildList.Count > 0); string DataAttr = ""; if (NodeKeys.Count > 0) { DataAttr = " data=\"({ ids: [" + string.Join(",", CurrentNode.Keys.ToArray()) + "] })\""; } string html = "<div class=\"TreeNode\" id=\"" + BaseId + "_TreeNode" + CurrentNode.Id + "\"" + DataAttr + "><span id=\"" + BaseId + "_TreeNodePrefix" + CurrentNode.Id + "\">" + prefix + "</span>"; if (HasChild && IsLastNode) { OpenCloseImage.Id = BaseId + "_TreeNodeState" + CurrentNode.Id; if (CurrentNode.Open) { OpenCloseImage.Src = BaseFolder + "tree/minusbottom.gif"; } else { OpenCloseImage.Src = BaseFolder + "tree/plusbottom.gif"; } OpenCloseImage.SetAttribute("onclick", string.Format(BaseId + ".changeState('{0}','{1}','{2}')", CurrentNode.Id, CurrentNode.Icon, CurrentNode.IconOpen)); html += OpenCloseImage.ToHtml(); } else if (HasChild && !IsLastNode) { OpenCloseImage.Id = BaseId + "_TreeNodeState" + CurrentNode.Id; if (CurrentNode.Open) { OpenCloseImage.Src = BaseFolder + "tree/minus.gif"; } else { OpenCloseImage.Src = BaseFolder + "tree/plus.gif"; } OpenCloseImage.SetAttribute("onclick", string.Format(BaseId + ".changeState('{0}','{1}','{2}',null)", CurrentNode.Id, CurrentNode.Icon, CurrentNode.IconOpen)); html += OpenCloseImage.ToHtml(); } else if (!HasChild && IsLastNode) { OtherImage.Src = BaseFolder + "tree/joinbottom.gif"; html += OtherImage.ToHtml(); } else { OtherImage.Src = BaseFolder + "tree/join.gif"; html += OtherImage.ToHtml(); } if (EnableCheckbox) { html += "<input onclick=\"" + BaseId + ".checkNode(this,'" + CurrentNode.Id + "')\" type=\"checkbox\" name=\"" + BaseId + "_CHK\" value=\"" + CurrentNode.Id + "\" />"; } if (EnableNodeImage) { OtherImage.Id = BaseId + "_TreeNodeFolder" + CurrentNode.Id; if (HasChild) { if (CurrentNode.Open) { OtherImage.Src = (!string.IsNullOrEmpty(CurrentNode.IconOpen)) ? CurrentNode.IconOpen : BaseFolder + "tree/folderopen.gif"; } else { OtherImage.Src = (!string.IsNullOrEmpty(CurrentNode.Icon)) ? CurrentNode.Icon : BaseFolder + "tree/folder.gif"; } html += OtherImage.ToHtml(); } else { OtherImage.Src = BaseFolder + "tree/page.gif"; html += OtherImage.ToHtml(); } OtherImage.ClearAttribute("id"); } Text.SetAttribute("onclick", string.Format(BaseId + ".selectNode('{0}',{1})", CurrentNode.Id, IsLastNode.ToString().ToLower())); Text.SetAttribute("ondblclick", string.Format(BaseId + ".selectNodeDBL('{0}',{1})", CurrentNode.Id, IsLastNode.ToString().ToLower())); if (!string.IsNullOrEmpty(CurrentNode.Url)) { Text.Href = CurrentNode.Url; if (!string.IsNullOrEmpty(CurrentNode.Target)) { Text.SetAttribute("target", CurrentNode.Target); } } else if (HasChild) { Text.Href = "javascript:" + string.Format(BaseId + ".changeState('{0}','{1}','{2}',null)", CurrentNode.Id, CurrentNode.Icon, CurrentNode.IconOpen); } Text.TagContent = CurrentNode.Name; if (!string.IsNullOrEmpty(CurrentNode.Title)) { Text.SetAttribute("title", CurrentNode.Title); } html += Text.ToHtml() + "</div>"; if (HasChild) { string ss = ""; if (CurrentNode.Open) { ss = " style=\"display:block\""; } html += "<div class=\"TreeNodeChilds\" id=\"" + BaseId + "_TreeNodeChilds" + CurrentNode.Id + "\"" + ss + ">"; if (IsLastNode) { OtherImage.Src = BaseFolder + "tree/empty.gif"; } else { OtherImage.Src = BaseFolder + "tree/line.gif"; } prefix += OtherImage.ToHtml(); for (int i = 0; i < ChildList.Count; i++) { IsLastNode = (i == (ChildList.Count - 1)); html += RenderNode(prefix, (Level + 1), ChildList[i], IsLastNode); } html += "</div>"; } return(html); }