public TreeViewNodeRenderEventArgs(TreeViewNode node, object dataItem)
		{
			if(node == null)
				throw new ArgumentNullException("node");

			_node = node;
			_dataItem = dataItem;
		}
		public TreeViewNode(string name, string text, string url)
		{
			if(string.IsNullOrWhiteSpace(name))
				throw new ArgumentNullException("name");

			if(name.Contains("/"))
			{
				if(name.Length == 1)
					name = "@";
				else
					throw new ArgumentException();
			}

			_name = name.Trim();
			_text = text ?? string.Empty;
			_navigateUrl = url ?? string.Empty;
			_toolTip = string.Empty;
			_description = string.Empty;
			_fullPath = string.Empty;
			_selected = false;
			_visible = true;
			_parent = null;
			_cssClass = "item";
		}
Exemple #3
0
        private void RenderNode(HtmlTextWriter writer, TreeViewNode node, int depth, int index = 0)
        {
            if (node == null || (!node.Visible))
            {
                return;
            }

            string cssClass = node.CssClass ?? this.ItemCssClass;

            if (!string.IsNullOrWhiteSpace(node.Name))
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Id, node.Name);
            }

            if (node.Selected)
            {
                cssClass = Utility.ResolveCssClass(":selected", () => cssClass);
            }

            if (this.IsDropdown && node.Nodes.Count > 0)
            {
                cssClass = Utility.ResolveCssClass(":ui dropdown", () => cssClass);
            }

            if (!string.IsNullOrWhiteSpace(cssClass))
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Class, cssClass);
            }

            writer.RenderBeginTag(this.GetItemTagName());

            if (!string.IsNullOrWhiteSpace(node.NavigateUrl))
            {
                if (!string.IsNullOrWhiteSpace(node.NavigateCssClass))
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, node.NavigateCssClass);
                }

                writer.AddAttribute(HtmlTextWriterAttribute.Href, node.NavigateUrl == "#" ? Utility.EmptyLink : node.NavigateUrl);
                writer.RenderBeginTag(HtmlTextWriterTag.A);
            }

            if (node.Image != null)
            {
                node.Image.ToHtmlString(writer);
            }

            writer.WriteEncodedText(node.Text);

            if (!string.IsNullOrWhiteSpace(node.NavigateUrl))
            {
                writer.RenderEndTag();
            }

            if (node.Nodes.Count > 0)
            {
                cssClass = node.ListCssClass;

                if (this.IsDropdown)
                {
                    cssClass = Utility.ResolveCssClass(":menu", () => cssClass);
                }

                if (!string.IsNullOrWhiteSpace(cssClass))
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, cssClass);
                }

                writer.RenderBeginTag(this.GetListTagName());

                int childIndex = 0;

                foreach (var child in node.Nodes)
                {
                    this.RenderNode(writer,
                                    child,
                                    depth + 1, childIndex++);
                }

                writer.RenderEndTag();

                //添加下拉箭头图标
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "icon dropdown");
                writer.RenderBeginTag(HtmlTextWriterTag.I);
                writer.RenderEndTag();
            }

            if (!string.IsNullOrWhiteSpace(this.LoadingPath) && string.Equals(this.LoadingPath, node.FullPath, StringComparison.OrdinalIgnoreCase))
            {
                this.RenderDataNodes(writer, this.DataSource as IEnumerable, depth, index, true);
            }

            writer.RenderEndTag();
        }
		public TreeViewNodeRenderEventArgs(TreeViewNode node) : this(node, null)
		{
		}
 public TreeViewNodeRenderEventArgs(TreeViewNode node) : this(node, null)
 {
 }