After searching for the tree for a long time on the Internet, I did not find the tree drop-down list, so I wrote one myself. (I am busy with work and have no time. It's easy to share this time, what are the shortcomings?ProgramMembers and comrades give a comment
Function: Infinite tree drop-down list, bound to a database
Table Structure: at least two fields, [ID, father_id] (preferably varchar type), are required to form a parent-child relationship.
DetailsCode:
// Data Acquisition
Protected void dropdatacon ()
{
Dataset DS = getdroplistdate (); // This is the data table that obtains the drop-down list, that is, the table above.
This. viewstate ["dataset"] = Ds;
Adddropdownlistitem (start ID );
Drop_dirlist.items.insert (0, new listitem (@ "/", start ID ));
}
// Recursively generate a tree drop-down list
Private Static string nbsp = ""; // public variable (required)
Protected void adddropdownlistitem (string ID) // This ID parameter is generated from that level (start ID)
{
Dataset DS = (Dataset) This. viewstate ["dataset"];
Dataview DV = new dataview (Ds. Tables [0]);
DV. rowfilter = "father_id = '" + ID + "'";
Foreach (datarowview DRV in DV)
{
Drop_dirlist.items.add (New listitem (nbsp + DRV ["dir_name"]. tostring (), DRV ["dir_id"]. tostring ()));
Nbsp + = "";
Adddropdownlistitem (DRV ["dir_id"]. tostring ());
Nbsp = nbsp. Remove (nbsp. Length-2 );
}
}