Home >
Article > Web Front-end > High-performance TreeView supplement based on JQUERY in ASP.NET_jquery
High-performance TreeView supplement based on JQUERY in ASP.NET_jquery
WBOYOriginal
2016-05-16 18:10:22900browse
The complete code is posted below. I took a lot of detours because I read the codes of friends in the replies. Now that I think about it, it doesn’t have to be that troublesome.
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; } //Recursive 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; } }
In the end, everyone can just build the database. Thanks again for being unfair. elder brother
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn