Bind componentart. Web. UI. Treeview control to SQL (original)

Source: Internet
Author: User
For reference
Protected void page_load (Object sender, eventargs E)
{
If (! Page. ispostback)
{
Bindtreeview ();
Treestaff. expandall ();
}
}

Protected override void onloadcomplete (eventargs E)
{
Base. onloadcomplete (E );
// Datatable dt = (grdlist. datasource as dataset). Tables [0];
String corpcode = globals. getcurrentusercorpcode ();
For (INT I = 0; I <grdlist. Items. Count; I ++)
{
Dataset DS = new ide_departmentcontroller (). getide_departmentbycorpcode (corpcode );
Treeviewnode treenode = getnodebyname (treestaff. nodes [0], DS. Tables [0]. Rows [0]. itemarray [5]. tostring ());
Treeviewnode treeuser = new treeviewnode ();
Treeuser. Text = grdlist. items [I]. cells [1]. text;
Treeuser. value = Ds. Tables [0]. Rows [0]. itemarray [5]. tostring ();
Treeuser. imageurl = "user8.gif ";
Treenode. nodes. Add (treeuser );
}

}

Private void bindtreeview ()
{
Dataset dssource = new ide_departmentcontroller (). getide_departmentbycorpcode (globals. getcurrentusercorpcode ());
Datarelation relation = new datarelation ("parentcode", dssource. tables [0]. columns ["departmentcode"], dssource. tables [0]. columns ["parentcode"], false );

Dssource. relations. Add (relation );
Datarow [] drsroot = dssource. Tables [0]. Select ("parentcode = ''");
Ide_corpinfoinfo corpinfo = new ide_corpinfocontroller (). getide_corpinfobycorpcode (globals. getcurrentusercorpcode ());
If (corpinfo = NULL)
Return;
Treeviewnode rootnode = new treeviewnode ();
Rootnode. Text = corpinfo. corpname;
Rootnode. value = "";
Rootnode. Expanded = true;

Foreach (datarow DR in drsroot)
{
Treeviewnode node = new treeviewnode ();
Node. Text = Dr ["departmentname"]. tostring ();
Node. value = Dr ["departmentcode"]. tostring ();
Buildchildnode (DR, node); // The root node under the LH-5-24 subnode cannot display the comment and the sentence is OK.
Rootnode. nodes. Add (node );
}
This. treestaff. nodes. Add (rootnode );

// Treeview2.datasource = dssource; treeview2.databind ();
}
Private void buildchildnode (datarow parentrow, componentart. Web. UI. treeviewnode parentnode)
{
Datarow [] drsub = parentrow. getchildrows ("parentcode ");
Foreach (datarow drchild in drsub)
{
Treeviewnode node = new treeviewnode ();
Node. Text = drchild ["departmentname"]. tostring ();
Node. value = drchild ["departmentcode"]. tostring ();
//
Parentnode. nodes. Add (node );
Buildchildnode (drchild, node );
}
}
/// <Summary>
/// Query the child nodes under the parent node that match the Department name
/// </Summary>
/// <Param name = "tvnode"> parent node </param>
/// <Param name = "departmentcode"> department code to be searched </param>
/// <Returns> </returns>
Protected treeviewnode getnodebyname (treeviewnode tvnode, string departmentcode)
{
If (tvnode = NULL)
{
Return NULL;
}
If (tvnode. value = departmentcode)
{
Return tvnode;
}
If (tvnode. nodes. Count = 0)
{
Return NULL;
}
For (INT I = 0; I <tvnode. nodes. Count; I ++)
{
Treeviewnode TVN = tvnode. nodes [I];
If (TVN. value = departmentcode)
{
Return TVN;
}
If (TVN. nodes. Count = 0)
{
Continue;
}
Treeviewnode tvchild = getnodebyname (TVN, departmentcode );
If (tvchild! = NULL)
{
Return tvchild;
}
}
Return NULL;
}

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.