The following is a complete code, I walked a lot of detours, the reason is to see the reply to the Code of Friends, now think of it actually need not so much trouble.
Copy Code code 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 Code code 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;
}
}
The final database we'll just look at the building. Thanks again for the indecent brother.