Treeview non-XML data source binding

Source: Internet
Author: User
Back to Boyou about the Treeview binding issue, just once done before, just come up Code Share it.
Problem: http://www.cnblogs.com/ninetynine/archive/2007/08/08/847847.html
Environment: I have a product table. Both the Directory and product are in a table. There is a field to indicate whether it is a product or a directory.
The Code is as follows:
Pageload part: Protected   Void Page_load ( Object Sender, eventargs E)
{

If ( ! Ispostback)
{
String SQL =   " Select ID, name, parentid from [product] Where isproduct = '0' and ID <> 0 " ;
DT = Sqlhelper. executedataset (SQL). Tables [ 0 ];
Inittreeall ();
}
}

The actual Treeview construction method is as follows: 1 Private   Void Inittreeall ()
2 {
3 Treenode tmpnd;
4 Datarow [] rows = DT. Select ( " Parentid = "   +   " 0 and ID <> 0 " );
5 Foreach (Datarow Dr In Rows)
6 {
7 Tmpnd =   New Treenode (Dr [ " Name " ]. Tostring (), Dr [ " ID " ]. Tostring ());
8 Product_tree.nodes.add (tmpnd );
9 Tmpnd. Expanded =   True ;
10 Datarow [] rowss = DT. Select ( " Parentid = "   + Dr [ " ID " ]. Tostring ());
11 Foreach (Datarow DRR In Rowss)
12 {
13 Tmpnd. childnodes. Add ( New Treenode (DRR [ " Name " ]. Tostring (), DRR [ " ID " ]. Tostring (), "" , " UI/productlist. aspx? Id = " + DRR [ " ID " ]. Tostring (), " _ Blank " ));
14 Tmpnd. Expanded =   True ;
15 }
16 }
17 Product_tree.expandall ();
18 }

For the actual binding effect, see: http://www.over-value.com on the left of the product list effect, I am doing a user control.

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.