Implement the binding of the Treeview Control Using recursive Methods

Source: Internet
Author: User

Implement the binding of the Treeview Control Using recursive Methods
Protected void page_load (Object sender, eventargs E)
{
If (this. Page. ispostback)
Return;
Treenode node = new treenode ();
Node. Text = "China ";
Node. value = "-1 ";
Treeview1.datasource = NULL; // treeview1 is empty
Treeview1.nodes. Add (node );
Treeview1.collapseall ();
Bindtreeview (0, node );
}

# Region Binding data
// Self-called entry condition

Private void bindtreeview (INT parentid, treenode nodes)
{
Province Pclass = new province ();
Pclass. ID = parentid. tostring ();
String SQL = "select * from province where code = '" + Pclass. ID "'";
Dataset DS = sqlfunction. returndataset (SQL );

Treenode node;
For (INT I = 0; I <Ds. Tables [0]. Rows. Count; I ++)
{
Node = new treenode ();
Node. Text = Ds. Tables [0]. Rows [I] ["name"]. tostring ();
Node. value = Ds. Tables [0]. Rows [I] ["ID"]. tostring ();
Nodes. childnodes. Add (node );
Bindtreeview (convert. toint32 (Ds. Tables [0]. Rows [I] ["ID"]), node );
}
}

# Endregion

 

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;

/// Import the namespace
Using system. Web. UI. webcontrols;

/// <Summary>
/// Summary description for treeviewdataleveldisplay
/// </Summary>
Public class treeviewdataleveldisplay
{
# Region declare global variables
Softwaretailor. LMS. model. Department model = new softwaretailor. LMS. model. Department ();
# Endregion

Public treeviewdataleveldisplay ()
{
//
// Todo: Add constructor logic here
//
}

/// <Summary>
/// Implement data binding for tree controls
/// </Summary>
/// <Param name = "Treeview"> tree control </param>
/// <Param name = "parentid"> parent id </param>
Public static void treeviewdataband (Treeview, guid parentid)
{
Treeview. nodes. Clear ();
List <softwaretailor. LMS. model. Department> List = softwaretailor. LMS. BLL. Department. getlistbyparentid (parentid, "createddate ASC ");
Treenode node;

If (list! = NULL & list. Count> 0)
{
Foreach (softwaretailor. LMS. model. Department model in List)
{
Node = new treenode ();
Node. Text = model. departmentname;
Node. value = model. inclumentid. tostring ();
Gettreeviewdataleveldisplay (model. extends mentid, node );
Treeview. nodes. Add (node );
}
}

}

/// <Summary>
/// Display data at the tree control level
/// </Summary>
/// <Param name = "parentid"> parent id </param>
/// <Param name = "nodes"> tree node </param>
Public static void gettreeviewdataleveldisplay (guid parentid, treenode nodes)
{
List <softwaretailor. LMS. model. Department> List = new list <softwaretailor. LMS. model. Department> ();
List = softwaretailor. LMS. BLL. Department. getlistbyparentid (parentid, "createddate ASC ");
If (list = NULL | list. Count = 0)
{
Return;
}
Treenode node;
Foreach (softwaretailor. LMS. model. Department model in List)
{
Node = new treenode ();
Node. Text = model. departmentname;
Node. value = model. inclumentid. tostring ();
Nodes. childnodes. Add (node );
Gettreeviewdataleveldisplay (model. extends mentid, node );
}
}

}

 

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.