The younger brother was very clumsy in writing. If you have any experts, please give me some advice and let the younger brother learn and learn...
Load tree -- use recursion
Protected void loadchannel ()
{
Datatable dt = bllchannel. getlist ();
Datarow [] parent = DT. Select ("parentid = 0 ");
Foreach (datarow parentrow in parent)
{
Treenode node = new treenode (parentrow ["title"]. tostring (), parentrow ["ID"]. tostring ());
Node. tooltip = parentrow ["title"]. tostring () + "=>" + parentrow ["ID"]. tostring (); // This is to use js to get the node's text and value.
Bindtree (DT, node, parentrow ["ID"]. tostring ());
Treeview1.nodes. Add (node );
}
}
Void bindtree (datatable DT, treenode node, string parentid)
{
Datarow [] ROW = DT. Select ("parentid =" + parentid );
Foreach (datarow R in row)
{
Treenode n = new treenode (R ["title"]. tostring (), R ["ID"]. tostring ());
N. tooltip = R ["title"]. tostring () + "=>" + R ["ID"]. tostring ();
Node. childnodes. Add (N );
Bindtree (DT, N, R ["ID"]. tostring ());
}
}
JS to get the value of the selected node and put it into two arrays respectively
VaR textarr = new array ();
VaR valuearr = new array ();
$ ("Input [type = 'checkbox']: checked"). Each (function (){
VaR TV = $ (this). ATTR ("title"). Split ("=>"); // The tooltip value above is very earthy.
Textarr. Push (TV [0]);
Valuearr. Push (TV [1]);
});
// Use join to convert the array into a string separated by "|" and fill in two text fields respectively.
$ Get ("catanam"). setattribute ("value", textarr. Join ("| "));
$ Get ("cataid"). setattribute ("value", valuearr. Join ("| "));
// When loading, use the recursive traversal tree to select the matching values
{
String [] cataidarray = row ["categoryid"]. tostring (). split (New String [] {"|"}, stringsplitoptions. removeemptyentries); // separate the values inserted into the database.
Checknode (treeview1.nodes, cataidarray );
}
// Recursive Method
Void checknode (treenodecollection tnodes, string [] cataidarray)
{
Foreach (treenode tn in tnodes)
{
For (INT I = 0; I <cataidarray. length; I ++)
{
If (TN. value = cataidarray. getvalue (I). tostring ())
{
Tn. Checked = true;
}
}
Checknode (TN. childnodes, cataidarray );
}
}
I beg the experts to help my younger brother give me some advice, because if there is a large amount of data, I am afraid I will not be able to afford it ....