asp.net实现递归方法取出菜单并显示在DropDownList中(分栏形式)
本文实例讲述了asp.net实现递归方法取出菜单并显示在DropDownList中的方法。分享给大家供大家参考,具体如下:
树形栏目展示以DropDownList的形式显示出来。
protectedvoidPage_Load(objectsender,EventArgse) { if(!IsPostBack) { DataTabletable=bllSite.GetChannelNames(CurrentUser.ParkID); BindChannelType(table,0,0); } } //递归方法取 privatevoidBindChannelType(DataTabledt,intcategoryid,intlayer) { DataViewdv=newDataView(dt); dv.RowFilter="Pid="+categoryid.ToString();//过滤 if(categoryid!=0) { layer++;//默认为第一层 } foreach(DataRowViewdrvindv) { stringspan=""; if(categoryid!=0) { for(inti=0;i<layer;i++)//父级菜单不缩进 { span+=""; } span+="└"; } ListItemli=newListItem(); li.Text=span+drv["ChannelName"].ToString(); li.Value=drv["Id"].ToString(); this.ddlChannel.Items.Add(li); BindChannelType(dt,Convert.ToInt32(drv["Id"]),layer); } }
更多关于asp.net相关内容感兴趣的读者可查看本站专题:《asp.net字符串操作技巧汇总》、《asp.net操作XML技巧总结》、《asp.net文件操作技巧汇总》、《asp.netajax技巧总结专题》及《asp.net缓存操作技巧总结》。
希望本文所述对大家asp.net程序设计有所帮助。