TreeView binding unlimited hierarchical relationship class

Source: Internet
Author: User

Protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {Bind_ TV (TreeView1.Nodes) ;}# add parent node to region // Add parent node // private void Bind_ TV (TreeNodeCollection tree) {// first add Level 1 parent node uint id = Convert. toUInt32 (Session ["ID"]); // Login User idstring sqlmcount = "select * from account where status = 1 and id = '" + id + "'"; dataTable Trdtmcount = MySqlDbHelper. getDataTable (sqlmcount, null); if (Trdtmcount. rows. count> 0) {TreeNode tn = new TreeNode (); tn. value = Trdtmcount. rows [0] ["id"]. toString (); tn. text = Trdtmcount. rows [0] ["nickname"]. toString (); tree. add (tn); BindSon (Convert. toUInt32 (Trdtmcount. rows [0] ["id"]), tn. childNodes ); // Add a subnode according to the parent node} # endregion # region recursively Add a subnode // private void BindSon (uint fatherid, treeNodeCollection tree) {string sqlMancount = "select id, nickname from account where masterid =" + fatherid + ";"; DataTable sonDT = MySqlDbHelper. getDataTable (sqlMancount, null); DataView dv = new DataView (sonDT); foreach (DataRowView item in dv) {// determine whether this person id has subordinates if (sonDT. rows. count> 0) // There are {TreeNode sontn = new TreeNode (); sontn. value = item ["id"]. toString (); sontn. text = item ["nickname"]. toString (); tree. add (sontn); BindSon (Convert. toUInt32 (item ["id"]), sontn. childNodes) ;}}# endregion

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.