asp.net implement recursive method to remove menu and display in DropDownList (column form) _ Practical Tips

Source: Internet
Author: User

This article illustrates the method of ASP.net implementation recursive method to remove a menu and display it in DropDownList. Share to everyone for your reference, specific as follows:

The tree-shaped column display is shown in DropDownList form.

 protected void Page_Load (object sender, EventArgs e) {if (!
      IsPostBack) {DataTable table = Bllsite.getchannelnames (Currentuser.parkid);
    Bindchanneltype (table, 0, 0);
    }///recursive method takes private void Bindchanneltype (DataTable dt, int categoryid, int layer) {DataView DV = new DataView (DT); Dv. RowFilter = "pid=" + CategoryID. ToString ();  Filter if (CategoryID!= 0) {layer++///default to First level} foreach (DataRowView drv in DV) {string
      span = "";
        if (CategoryID!= 0) {for (int i = 0; i < layer i++)//parent menu does not indent {span + = "";
      span + = "└";
      } ListItem li = new ListItem (); Li. Text = span + drv["channelname"].
      ToString (); Li. Value = drv["Id"].
      ToString ();
      This.ddlChannel.Items.Add (LI);
    Bindchanneltype (DT, Convert.ToInt32 (drv["Id"]), layer); }
}

More interested readers of asp.net related content can view the site topics: "asp.net string operation tips Summary", "ASP.net Operation XML Skills summary", "asp.net file Operation skills Summary", "ASP.net Ajax Skills Summary topics" and " Summary of ASP.net caching operation techniques.

I hope this article will help you to ASP.net program design.

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.