Generate a three-level tree menu

Source: Internet
Author: User
Tags id3

Private void gettree ()
{
Datatable dt1 = new datatable ();
Datatable dt2 = new datatable ();
Datatable dt3 = new datatable ();
If (strbbstype = "1 ")
{
Dt1 = sqlhelper. executedataset (sqlhelper. Conn, commandtype. Text, "select ID, menuname, URL from m_menuhead"). Tables [0];
Dt2 = sqlhelper. executedataset (sqlhelper. Conn, commandtype. Text, "select ID, PID, menuname from m_menuchildren"). Tables [0];
Dt3 = sqlhelper. executedataset (sqlhelper. Conn, commandtype. Text, "select ID, PID, ppid, menuname from m_menuchildren2"). Tables [0];
}
Else
{
Dt1 = sqlhelper. executedataset (sqlhelper. Conn, commandtype. Text, "select ID, panelname as menuname, URL from bbs_panel1"). Tables [0];
Dt2 = sqlhelper. executedataset (sqlhelper. Conn, commandtype. Text, "select ID, PID, panelname as menuname from bbs_panel2"). Tables [0];
Dt3 = sqlhelper. executedataset (sqlhelper. Conn, commandtype. Text, "select ID, PID, panelname as menuname from bbs_panel3"). Tables [0];
}
Int count1 = dt1.rows. count;
Int count2 = dt2.rows. count;
Int count3 = dt3.rows. count;
String COUNT = "";
Int I = 0;
Int J = 0;
Int K = 0;
String pid2 = "";
String Id2 = "";
String pid3 = "";
String ID3 = "";
Stringbuilder SB1 = new stringbuilder ("<ul id = 'tree' class = 'treeview'> ");
For (I = 0; I <count1; I ++)
{

Sb1.append ("<li class = 'pandable'> <Div class = 'hitarea expandable-hitare'> </div> <a href = 'title. aspx? Mode = 1 & id = "+ Id2 +" 'target = 'main'> <strong> "+ dt1.rows [I] [" menuname "]. tostring () + "</strong> </a> ");
Sb1.append ("<ul style = 'display: none; '> ");
For (j = 0; j <count2; j ++)
{Pid2 = dt2.rows [J] ["PID"]. tostring ();
Id2 = dt1.rows [I] ["ID"]. tostring ();
If (pid2 = Id2)
{
Count = sqlhelper. executescalar (sqlhelper. Conn, commandtype. Text, "select count (ID) from m_menuchildren2 where pid =" + Id2 + ""). tostring ();
If (COUNT = "0 ")
{
Sb1.append ("<li> <a href = 'title. aspx? Mode = 2 & id = "+ pid2 +" & pid = "+ ID3 +" 'target = 'main'> "+ dt2.rows [J] [" menuname "]. tostring () + "</a> ");

}
Else
{
Sb1.append ("<li class = 'pandable'> <a href = 'title. aspx? Mode = 2 & id = "+ pid2 +" & pid = "+ ID3 +" 'target = 'main'> "+ dt2.rows [J] [" menuname "]. tostring () + "</a> ");
Sb1.append ("<ul style = 'display: none; '> ");
}
For (k = 0; k <count3; k ++)
{
Pid3 = dt3.rows [k] ["PID"]. tostring ();
ID3 = dt2.rows [J] ["ID"]. tostring ();
If (pid3 = ID3)
{
Sb1.append ("<li> <a href = 'title. aspx? Mode = 3 & id = "+ dt3.rows [k] [" ppid "]. tostring () + "& pid =" + dt3.rows [k] ["PID"]. tostring () + "& ppid =" + dt3.rows [k] ["ID"]. tostring () + "'target = 'main'>" + dt3.rows [k] ["menuname"]. tostring () + "</a> </LI> ");
}
}
If (COUNT = "0 ")
{
Sb1.append ("</LI> ");
}
Else
{
Sb1.append ("</ul> ");
Sb1.append ("</LI> ");
}
}
}
Sb1.append ("</ul> ");
Sb1.append ("</LI> ");
}
Sb1.append ("</ul> ");

Sidetreecontrol. innerhtml = sb1.tostring ();
}

Private void gettree2 ()
{
Datatable dt1 = new datatable ();
Datatable dt2 = new datatable ();
Datatable dt3 = new datatable ();
Dt1 = sqlhelper. executedataset (sqlhelper. Conn, commandtype. Text, "select ID, menuname, URL from m_menuhead"). Tables [0];

Int count1 = dt1.rows. count;
Int count2 = 0;
Int count3 = 0;
String COUNT = "";
Int I = 0;
Int J = 0;
Int K = 0;
String pid2 = "";
String Id2 = "";
String pid3 = "";
String ID3 = "";

Stringbuilder SB1 = new stringbuilder ("<ul id = 'tree' class = 'treeview'> ");
For (I = 0; I <count1; I ++)
{
Id2 = dt1.rows [I] ["ID"]. tostring ();
Sb1.append ("<li class = 'pandable'> <Div class = 'hitarea expandable-hitare'> </div> <a href = 'title. aspx? Mode = 1 & id = "+ Id2 +" 'target = 'main'> <strong> "+ dt1.rows [I] [" menuname "]. tostring () + "</strong> </a> ");
Sb1.append ("<ul style = 'display: none; '> ");
Dt2 = sqlhelper. executedataset (sqlhelper. Conn, commandtype. Text, "select ID, PID, menuname from m_menuchildren where pid =" + Id2 + ""). Tables [0];
Count2 = dt2.rows. count;
For (j = 0; j <count2; j ++)
{
Dt3 = sqlhelper. executedataset (sqlhelper. conn, commandtype. text, "select ID, PID, ppid, menuname from m_menuchildren2 where pid =" + dt2.rows [J] ["ID"]. tostring () + ""). tables [0];
Count3 = dt3.rows. count;

Sb1.append ("<li class = 'pandable'> <a href = 'title. aspx? Mode = 2 & id = "+ pid2 +" & pid = "+ ID3 +" 'target = 'main'> "+ dt2.rows [J] [" menuname "]. tostring () + "</a> ");
Sb1.append ("<ul style = 'display: none; '> ");

For (k = 0; k <count3; k ++)
{
Sb1.append ("<li> <a href = 'title. aspx? Mode = 3 & id = "+ dt3.rows [k] [" ppid "]. tostring () + "& pid =" + dt3.rows [k] ["PID"]. tostring () + "& ppid =" + dt3.rows [k] ["ID"]. tostring () + "'target = 'main'>" + dt3.rows [k] ["menuname"]. tostring () + "</a> </LI> ");
}
Sb1.append ("</ul> ");
Sb1.append ("</LI> ");
}
Sb1.append ("</ul> ");
Sb1.append ("</LI> ");
}
Sb1.append ("</ul> ");

Sidetreecontrol. innerhtml = sb1.tostring ();
}

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.