DropDownList中如何添加2级下拉菜单

  
    
if ( ! IsPostBack)
{
List
< Model.categroy > list = new DAL.categroy().GetListArray( "" );
//取出所有数据放入泛型list中 效率更高
var q
= list.Where(x => x.pid == 0 );
//linq语句 x代表list中的每一项 如果pid为0则取出放入q中
foreach (Model.categroy item in q)
{
DropDownList1.Items.Add(
new ListItem(item.caname,item.id.ToString()));
//父级菜单
var q2
= list.Where(y => y.pid == item.id);

foreach (var item2 in q2)
{
DropDownList1.Items.Add(
new ListItem( " ...... " + item2.caname, item2.id.ToString()));
//二级菜单

}
}
}

你可能感兴趣的:(list)