Unlimited classification is often used for classification. First, we will introduce the table structure of the database.
Tid category No.
Tname category name
Pid parent class ID
Test data will not be written. you can insert the data and try again.
Queries the code of all sub-class SQL statements of a specific category.
Copy codeThe Code is as follows: alter proc proc_chaxun
(@ Tid int)
As
Begin
With tt
(
Select tid, tname, pid from dbo. t_goodsType where tid = @ tid
Union all
Select t. tid, t. tname, t. pid from dbo. t_goodsType t inner join tt
On t. pid = tt. tid
)
Select * from tt
End
Obtain the record set after query and bind it to the foreground TreeView.
Copy codeThe Code is as follows: // <summary>
/// Recursively add subnodes to the Tree
/// </Summary>
/// <Param name = "dv"> data view </param>
/// <Param name = "tnOld"> Add a data node </param>
Public void TreeDataBind (DataView dv, TreeNode tnOld)
{
TreeNode tnNew; // create a new node
Foreach (DataRowView drv in dv)
{
// Set attributes for the new borrow point
TnNew = tnOld. Nodes. Add (drv ["tname"]. ToString ());
TnNew. Tag = drv ["tid"];
// Filter data view parent class id = tid of the upper level
Dv. RowFilter = "pid =" + drv ["tid"]. ToString ();
// Call yourself
TreeDataBind (dv, tnNew );
}
}
The call method is simple.
Copy codeThe Code is as follows: DataTable dtRet = (DataTable) dh. ExecProcRetObj (ep );
DataView dv = new DataView (dtRet );
Dv. RowFilter = "pid = 0 ";
TreeDataBind (dv, this. treeView1.Nodes. Add ("item category "));
Effect