Use of the Treeview Control

Source: Internet
Author: User

A piece of code written using the Treeview control takes n long to come out.

Protected void treeview1_load ()
{
// Fill in treeview1
Sqlcommand mycommand1 = new sqlcommand ("select * from chapter where course_id = 0", myconn );
Sqldatareader DR1 = mycommand1.executereader ();
// Sqldataadapter da1 = new sqldataadapter (mycommand1 );
// Dataset ds1 = new dataset ("Temp ");
// Da1.fill (ds1 );

Sqlcommand mycommand2;
Sqldatareader DR2;


While (dr1.read ())
{
Treenode newnode = new treenode (DR1 ["chapter_name"]. tostring ());
Newnode. value = DR1 ["chapter_id"]. tostring ();
Newnode. Collapse ();
// L2 node --->
// Mycommand2 = new sqlcommand ("select * from section where chapter_id =" + DR1 ["chapter_id"]. tostring (), myconn );
// DR2 = mycommand2.executereader ();
// Treenode newnode2 = new treenode (DR2 ["section_name"]. tostring ());
// Newnode. childnodes. Add (newnode2 );
// <-----

Treeview1.nodes. Add (newnode );

}
Dr1.close ();

Foreach (treenode newnode in treeview1.nodes)
{
Mycommand2 = new sqlcommand ("select * from section where chapter_id =" + newnode. value. tostring (), myconn );
DR2 = mycommand2.executereader ();
While (dr2.read ())
{
Treenode tempnode = new treenode (DR2 ["section_name"]. tostring ());
Tempnode. navigateurl = "#";
Tempnode. Target = "_ blank ";
Newnode. childnodes. Add (tempnode );

}
Dr2.close ();
}

/*
If (ds1.tables ["chapter"]. Rows. Count. compareto (0)> 0)
{
Foreach (datarow row in ds1.tables ["chapter"]. Rows)
{
Treenode newnode = new treenode (row ["chapter_name"]. tostring ());
// L2 node --->
Mycommand2 = new sqlcommand ("select * from section where chapter_id =" + row ["chapter_name"]. tostring (), myconn );
DR2 = mycommand2.executereader ();
Treenode newnode2 = new treenode (DR2 ["section_name"]. tostring ());
Newnode. childnodes. Add (newnode2 );
// <---------
Treeview1.nodes. Add (newnode );
}
}
Ds1.dispose ();
*/
}

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.