/// <summary>
/// 初始化菜单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ShowList();
}
}
/// <summary>
/// 添加根节点,调用递归函数
/// </summary>
public void ShowList()
{
TVMenu.Nodes.Clear();
TreeNode node = new TreeNode();
node.Text = "个人网站管理";
node.Target = "2";
node.Expanded = true;
BindToTree(node, 2);
TVMenu.Nodes.Add(node);
TVMenu.DataBind();
}
/// <summary>
/// 递归初始化菜单
/// </summary>
/// <param name="PNode">树节点</param>
/// <param name="menuType">父节点ID</param>
public void BindToTree(TreeNode PNode, int menuType)
{
DataSet ds = Menu.GetChildMenu(menuType);
if (ds != null)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
TreeNode node = new TreeNode();
node.Target = "body";
node.NavigateUrl = ds.Tables[0].Rows[i]["menuUrl"].ToString();
node.Text = ds.Tables[0].Rows[i]["menuName"].ToString();
PNode.ChildNodes.Add(node);
PNode.Expanded = true;
DataSet child = Menu.GetChildMenu(Convert.ToInt32(ds.Tables[0].Rows[i]["menuID"]));
if (child.Tables[0].Rows.Count > 0)
{
BindToTree(node, Convert.ToInt32(ds.Tables[0].Rows[i]["menuID"]));
}
}
}
}