树形菜单
//树形菜单
protected void GetTree()
{
DataTable dt = new MenuBll().GetAll();
DataView dv = dt.DefaultView;
dv.RowFilter = "PId =0";
foreach (DataRowView drv in dv)
{
TreeNode tn = new TreeNode();
tn.Text = drv["MenuName"].ToString();
tn.Value = drv["Id"].ToString();
tn.NavigateUrl = drv["Url"].ToString();
tn.ImageUrl = "~/images/open.ico";
tn.Target = "mainFrame";
MenuTree.Nodes.Add(tn);
GrtTreeNode(dt, tn);
}
}
protected void GrtTreeNode(DataTable dt, TreeNode ptn)
{
DataView dv = dt.DefaultView;
dv.RowFilter = "PId =" + ptn.Value;
foreach (DataRowView drv in dv)
{
TreeNode tn = new TreeNode();
tn.Text = drv["MenuName"].ToString();
tn.Value = drv["Id"].ToString();
tn.NavigateUrl = drv["Url"].ToString();
tn.ImageUrl = "~/images/file.ico";
tn.Target = "mainFrame";
ptn.ChildNodes.Add(tn);
GrtTreeNode(dt, tn);
}
}