JQUERY-based high-performance TreeView supplement in ASP. NET

Source: Internet
Author: User

The complete code is pasted below, and I have taken a lot of detours, because I read the code from my friends in the reply. Now I don't have to bother with it.
Copy codeThe Code is as follows:
<Script src = "js/jquery-1.4.2.min.js" type = "text/javascript"> </script>
<Script src = "js/jquery. mytree. js" type = "text/javascript"> </script>
<Link href = "second.css" rel = "stylesheet" type = "text/css"/>
<Script type = "text/javascript">
$ (Function (){
Var o = {showcheck: true };
O. data = <% = treeNodes %>;
$ ("# Tree"). treeview (o );
})
</Script>

Background
Copy codeThe Code is as follows:
Public string GetFirJson ()
{
String mystr = "[";
DataTable dt = DBUtility. db. ExecuteTable ("select * from class where parientid = 0 ");
Int a = dt. Rows. Count;
For (int I = 0; I <= dt. Rows. Count-1; I ++)
{
Mystr + = GetOtherJson (Convert. ToInt32 (dt. Rows [I] ["classid"]. ToString () + ",";
}
Mystr = mystr. Substring (0, mystr. Length-1 );
Mystr + = "]";
Mystr = mystr. Replace ("'","\"");
Return mystr;
}
// Recursion
Private string GetOtherJson (int pid)
{
DataTable dt = DBUtility. db. ExecuteTable ("select * from class where classid =" + pid );
String strjson = "";
Bool haschild = IsHasChild (pid );
Strjson = "{";
Strjson + = "'id': '" + pid + "',";
Strjson + = "'text': '" + dt. Rows [0] ["classname"]. ToString () + "',";
Strjson + = "'value': '" + dt. Rows [0] ["classid"]. ToString () + "',";
Strjson + = "'showcheck': true ,";
Strjson + = "'complete': true ,";
Strjson + = "'checktate': 0 ,";
Strjson + = "'haschildren ':" + haschild. ToString (). ToLower () + ",";
Strjson + = "'childnodes ':";
If (! IsHasChild (pid ))
{
Strjson + = "null }";
}
Else
{
Strjson + = "[";
DataTable mydt = DBUtility. db. ExecuteTable ("select * from class where parientid =" + pid );
For (int I = 0; I <= mydt. Rows. Count-1; I ++)
{
Strjson + = GetOtherJson (Convert. ToInt32 (mydt. Rows [I] ["classid"]. ToString () + ",";
}
Strjson = strjson. Substring (0, strjson. Length-1 );
Strjson + = "]}";
}
Return strjson;
}
Private bool IsHasChild (int pid)
{
DataTable dt = DBUtility. db. ExecuteTable ("select * from class where parientid =" + pid );
If (dt. Rows. Count = 0)
{
Return false;
}
Else
{
Return true;
}
}

Finally, you can just look at the database and build it. Thanks again, not serious.

Related Article

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.