Database Structure
Tb_department table
D_id department ID
D_name Department name
D_tel
D_address
D_chief owner,
Department of d_belong
Tb_employee table
E_id employee ID
E_name employee name
E_sex staff gender
E_tel
E_address
E_birth Date of birth
Department of d_name
Foreground aspx
<Asp: Treeview id = "treeview1" runat = "server" imageset = "FAQ" width = "162px">
<Parentnodestyle font-bold = "false"/>
<Hovernodestyle font-underline = "true" forecolor = "Purple"/>
<Selectednodestyle font-underline = "true" horizontalpadding = "0px" verticalpadding = "0px"/>
<Nodestyle font-names = "tahoma" font-size = "8pt" forecolor = "darkblue" horizontalpadding = "5px"
Nodespacing = "0px" verticalpadding = "0px"/>
</ASP: Treeview>
BackgroundCode Aspx. CS
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
Treeviewbind ();
}
}
# Region Master/Slave table binding
Private void treeviewbind ()
{
Sqlconnection Cn1 = new sqlconnection (configurationmanager. connectionstrings ["mispersonalconn"]. connectionstring );
Sqlcommand mycmd1 = new sqlcommand ("select * from [tb_department]", Cn1 );
Sqldataadapter da1 = new sqldataadapter (mycmd1 );
Dataset ds1 = new dataset ();
Da1.fill (ds1, "tb_department"); // read the category
For (INT I = 0; I <ds1.tables ["tb_department"]. Rows. Count; I ++)
{
Treenode TD1 = new treenode ();
Treenode departmentlist = new treenode ("department list ","","","","");
Treeview1.nodes. Add (departmentlist );
Td1.text = ds1.tables ["tb_department"]. Rows [I] ["d_name"]. tostring (); // list of major departments
Td1.value = ds1.tables ["tb_department"]. Rows [I] ["d_id"]. tostring ();
Td1.navigateurl = "~ /Webfiles/list. aspx? D_id = "+ td1.value +" & "+" d_name = "+ td1.text; // connection address
Departmentlist. childnodes. Add (TD1 );
sqlconnection cn2 = new sqlconnection (configurationmanager. connectionstrings ["mispersonalconn"]. connectionstring);
sqlcommand mycmd2 = new sqlcommand ("select * from [tb_employee] Where d_name = '" + ds1.tables ["tb_department"]. rows [I] ["d_name"]. tostring () + "'", cn2);
sqldataadapter da2 = new sqldataadapter (mycmd2);
dataset ds2 = new dataset ();
da2.fill (ds2, "tb_employee"); // reads small classes.
for (Int J = 0; j {< br> treenode td2 = new treenode ();
td2.text = ds2.tables ["tb_employee"]. rows [J] ["e_name"]. tostring (); // small class
// td2.navigateurl = "~ /Webfiles/list. aspx? D_id = {0} & d_name = {1} "; // connection address
td1.childnodes. Add (td2);
}< BR >}
treeview1.databind ();
}< BR ># endregion