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.