A small control that generates the HTML required for the jquery simple treeview

Source: Internet
Author: User

(Is loading VS2008, take this time to share the next small control, can not organize demo, only from the project copy part of the code)

JQuery simple TreeView needs such a piece of HTML

<ul class="filetree" id="treeFolder">
<li id="1"><span  class="folder">Root</span>
 <ul>
 <li id="2" class="closed"><span  class="folder">node1</span><ul></ul></li>
 <li id="22" class="closed"><span  class="folder">node2</span><ul></ul></li>
 <li id="23" class="closed"><span  class="folder">node3</span><ul></ul></li>
 </ul>
</li>
<li id="64"><span  class="imagebase">root2</span></li>
</ul>

Put an empty <ul></ul> on this side, because that node has a child node, but we did not load him, when the user clicks the expand button in the expansion. Expand the time to go to the server to take a data on their own add, here is no nonsense.

First code:

Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Text;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;

Namespace aaa.bbb.ccc//to change his own
{
[Defaultproperty ("Text")]
[ToolBoxData ("<{0}:javascripttree runat=server></{0}:javascripttree>")]
public class Javascripttree:webcontrol
{
Private list<javascripttreenode> _nodes = new list<javascripttreenode> ();
Public list<javascripttreenode> Nodes
{
Set
{
_nodes = value;
}
Get
{
return _nodes;
}
}

private string _classname;
public string ClassName
{
Get
{
return _classname;
}
Set
{
_classname = value;
}
}

protected override void CreateChildControls ()
{
Base. CreateChildControls ();
foreach (Javascripttreenode item in _nodes)
{
Base. Controls.Add (item);
}
}

public override void RenderBeginTag (HtmlTextWriter writer)
{
Writer. WriteBeginTag ("div");
Writer. WriteAttribute ("Class", this.) ClassName);
Writer. WriteAttribute ("id", "div" + this.id);
Writer. Write (Htmltextwriter.tagrightchar);

Writer. WriteBeginTag ("ul");
Writer. WriteAttribute ("Class", this.) ClassName);
Writer. WriteAttribute ("id", this.id);
Writer. Write (Htmltextwriter.tagrightchar);
}

public override void RenderEndTag (HtmlTextWriter writer)
{
Writer. Writeendtag ("ul");
Writer. Writeendtag ("div");
}

protected override HtmlTextWriterTag Tagkey
{
Get
{
return htmltextwritertag.div;
}
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.