private string buildSubString(int parentId, FuncMenuCollection _menu) { StringBuilder _sbSubString = new StringBuilder(); foreach (var subMenu in _menu.Where(x=>x.ParentID==parentId)) { _sbSubString.AppendFormat("<li ><a id='{0}?menuid={1}' onclick='changePage(this.id);' href='#'><span>{2}</span></a></li>", subMenu.Path,subMenu.ItemID, subMenu.Text); } return _sbSubString.ToString(); }
private void menuFunc( int userID) { StringBuilder _sbMenu = new StringBuilder(); MenuServiceClient _msc = new MenuServiceClient(); FuncMenuCollection _menuList = new FuncMenuCollection(_msc.QueryUserMenu(userID).GroupBy(x => x.Text).Select(x => x.First())); var _menuParentList = _menuList.Where(x => x.ParentID == 0).ToList(); _sbMenu.Append("<div id='divFuncMenu'>"); _sbMenu.Append("<ul>"); for (int i = 0; i < _menuParentList.Count; i++) { var _menu = _menuParentList[i]; _sbMenu.Append(buildString(_menuList.Any(x => x.ParentID == _menu.ItemID), i == _menuParentList.Count, _menu, _menuList)); } _sbMenu.Append("</ul></div>"); ltrFuncMenu.Text = _sbMenu.ToString(); }