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.