- protected void Page_Load(object sender, EventArgs e)
- { if (!IsPostBack)
- { BindMenu(); }
- }
- // <summary> /// 绑定手风琴目录
- //</summary>
- protected void BindMenu()
- { //ds就是就是数据库里查询出来的菜单数据,这里用 new DataSet()代替,具体的自己写;
- DataSet ds = new DataSet();
- ExtAspNet.Accordion accordion = new ExtAspNet.Accordion();
- Region2.Items.Add(accordion);
- accordion.ShowBorder = false;
- accordion.ShowHeader = false;
- //找出所有手风琴节点
- DataRow[] drParent = ds.Tables[0].Select("PrentID=0");
- //遍历创建每个手风琴节点
- foreach (DataRow dr in drParent)
- { ExtAspNet.AccordionPane pane = new ExtAspNet.AccordionPane();
- accordion.Panes.Add(pane);
- pane.Title = dr["NAME"].ToString();
- pane.ShowBorder = false;
- //创建该节点下的菜单目录,并将该手风琴节点的ID作为下属菜单的父节点
- CreateTree(ds, dr["ID"].ToString(), pane); } }
- // 绑定树状目录 /// </summary>
- protected void CreateTree(DataSet ds, string PrentID, ExtAspNet.AccordionPane pane)
- { DataRow[] drParent = ds.Tables[0].Select("PrentID=" + PrentID+ "");
- ExtAspNet.Tree tree = new ExtAspNet.Tree();
- pane.Items.Add(tree);
- tree.ShowBorder = false;
- tree.ShowHeader = false;
- tree.AutoScroll = false;
- tree.EnableArrows = true;
- foreach (DataRow dr in drParent)
- { ExtAspNet.TreeNode TN = new ExtAspNet.TreeNode();
- TN.NodeID = dr["ID"].ToString();
- TN.Text = dr["NAME"].ToString();
- TN.OnClientClick = mainTabStrip1.GetAddTabReference(dr["ID"].ToString(), dr["URL"].ToString() , dr["NAME"].ToString(), true);
- TN.EnablePostBack = false;
- tree.Nodes.Add(TN);
- CreateNodes(ds, dr["ID"].ToString(), TN); } }
- // 绑定子目录 /// </summary>
- protected void CreateNodes(DataSet ds, string PrentID, ExtAspNet.TreeNode TN)
- { DataRow[] drParent = ds.Tables[0].Select("PrentID=" + PrentID+ "");
- foreach (DataRow dr in drParent)
- { ExtAspNet.TreeNode tn = new ExtAspNet.TreeNode();
- tn.Text = dr["NAME"].ToString();
- tn.NodeID = dr["ID"].ToString();
- TN.OnClientClick = mainTabStrip1.GetAddTabReference(dr["ID"].ToString(), dr["PATH"].ToString(), dr["NAME"].ToString(), true);
- TN.EnablePostBack = false;
- TN.Nodes.Add(tn);
- //循环子节点看看是否还有下属节点
- CreateNodes(ds, dr["ID"].ToString(), tn); } }
- }
复制代码 |