private void GetMenuCount(System.Web.UI.Control parentCountol)//找到memu的个数
{
if (parentCountol.HasControls())
{
foreach (System.Web.UI.Control c in parentCountol.Controls)
{
if (c is System.Web.UI.WebControls.Menu)
{
BindTreeView(((System.Web.UI.WebControls.Menu)c).Items, TreeView1.Nodes);
}
GetMenuCount(c);
}
}
}
private void BindTreeView(MenuItemCollection menuItemCollection,TreeNodeCollection treeNodeCollection)//把menu绑定到treeview上
{
foreach (MenuItem menuItem in menuItemCollection)
{
TreeNode treeNode = new TreeNode();
treeNode.Text = menuItem.Text;
treeNode.ShowCheckBox = true;
treeNodeCollection.Add(treeNode);
if (menuItem.ChildItems.Count != 0)//递归
{
BindTreeView(menuItem.ChildItems,treeNode.ChildNodes);
}
}
}