[Retain backup] ASP. NET Dynamic Menu Generation common method

Source: Internet
Author: User
# Region ASP. NET Dynamic Menu Generation common method
Private void inittree0 (menu TV, dataset DS) // function for loading the root node
{
TV. Items. Clear (); // TV is the Treeview Control
Datarow [] rows = Ds. Tables [0]. Select ("parent_id = 0 ");
For (INT I = 0; I <rows. length; I ++)
{
Menuitem t_root = new menuitem ();
Datarow DR = rows [I];
T_root.text = Dr ["menu_name"]. tostring ();
T_root.target = Dr ["url"]. tostring ();
TV. Items. Add (t_root );
Inittree (t_root, Dr ["ID"]. tostring (), DS); // After the root node is loaded, call the function for loading the child node and start recursion.
}
}
Private void inittree (menuitem nd, string parent_id, dataset DS) // function for loading subtree nodes
{
Datarow [] rows = Ds. Tables [0]. Select ("parent_id =" + parent_id );
If (rows! = NULL)
{
For (INT I = 0; I <rows. length; I ++)
{
Menuitem TND = new menuitem ();
Datarow DR = rows [I];
TND. Text = Dr ["menu_name"]. tostring ();
TND. Target = Dr ["url"]. tostring ();
Nd. childitems. Add (TND );
Inittree (TND, Dr ["ID"]. tostring (), DS); // recursive call
}
}
}
# Endregion
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.