导航

[ASP.NET]ASP.NET数据绑定菜单控件

Posted on 2014-03-25 19:54  beeone  阅读(368)  评论(0编辑  收藏  举报
public void BindMenu(Menu mn,MenuItem menu,string mainMenu,string sql)   
        {   
                MenuItem mitem = null;   
                DB db = new DB();   
                DataSet ds = db.GetDataSet(sql, "table1");   
                DataTable dTable = ds.Tables[0];   
                DataRow[] drow = dTable.Select(" parentId='" + mainMenu + "'");   
                   
                foreach (DataRow dr in drow)   
                {   
                        mitem = new MenuItem();   
                        mitem.Text = dr["modulName"].ToString();   
                        mitem.Value = dr["modulId"].ToString();   
                        mitem.NavigateUrl = "Default.aspx";   
                        if (menu == null)   
                        {   
                                mn.Items.Add(mitem);   
                        }   
                        else   
                        {   
                                menu.ChildItems.Add(mitem);   
                        }   
                        DataSet dst = db.GetDataSet(sql, "table2");   
                        DataTable dtb = dst.Tables[0];   
                        DataRow[] dar = dtb.Select(" parentId='" + mitem.Value + "'");   
                        mainMenu = mitem.Value;   
                        BindMenu(Menu1, mitem, mainMenu, sql);   
                }   
        }