日期:2014-05-19  浏览次数:20503 次

如何通过数据库生成.NET导航菜单???
请教大家:如何通过后台数据库生成.NET导航菜单?象这样:http://www.zkbr.com/
这个问题困惑我几周了,请大家帮忙指点。在ASP文件中实现起来很麻烦,在.NET2.0中有没有更好更快的解决办法???

------解决方案--------------------
private void InitMenu(MenuItemCollection Nds, string ParentMenuID, DataSet ds)
{
string FilterMenu = " ";

if (ParentMenuID == "00 ")
FilterMenu = "len(MenuID)=2 ";
else
FilterMenu = "MenuID like ' " + ParentMenuID + "% 'and MenuID <> ' " + ParentMenuID + " 'and len(MenuID)= ' " + Convert.ToString(ParentMenuID.Length + 2) + " ' ";

using (DataView dv = new DataView())
{

dv.Table = ds.Tables[0];

dv.RowFilter = FilterMenu;

foreach (DataRowView drv in dv)
{
MenuItem myMenuItem = new MenuItem();
myMenuItem.NavigateUrl = drv[ "MenuNavigateUrl "].ToString();
myMenuItem.Target = drv[ "Target "].ToString();
myMenuItem.Text = drv[ "MenuTxt "].ToString();
myMenuItem.Value = drv[ "MenuID "].ToString();
if (ParentMenuID!= "00 ")
{
myMenuItem.ImageUrl = "../images/ahead.gif ";
}
Nds.Add(myMenuItem);
InitMenu(myMenuItem.ChildItems, myMenuItem.Value, ds);
}
}
}