C # Implementation of TreeView unlimited Classification

Source: Internet
Author: User

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

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.