/ Published in: C#
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
private void InitData(EOpenMode emOpenMode , string sDept) { //載入å„è©•åˆ†ç´°é …å³éµåŠŸèƒ½è¡¨ sql = "SELECT * FROM CallMonitorContextMenu"; if (mis.DBOpenSQL(sql, ref rs)) { categoryList.AddRange( label110, label120, label130, label140, label150, label160, label210, label220, label230, label240, label310, label320, label330, label340, label350, label360, label370} ); for (int i = 0; i < categoryList.Count; i++) { EnumerableRowCollection<DataRow> query = rs.AsEnumerable() .Where(row => row.Field<string>("Category") == categoryList[i].Text); categoryList[i].ContextMenuStrip = menu; EnumerableRowCollection<DataRow> querySubMenuItem = query.Where(row => row.Field<int>("ParentMenuId") == 0); foreach (var row in querySubMenuItem) { ToolStripMenuItem subMenuItem = (ToolStripMenuItem)menu.Items.Add(row.Field<string>("MenuText")); CreateSubMenu(query, subMenuItem, row.Field<int>("MenuId"), 1); } } } } private void CreateSubMenu(EnumerableRowCollection<DataRow> query, ToolStripMenuItem menu, int parentMenuId, int level) { if (level > 3) return; EnumerableRowCollection<DataRow> querySubMenuItem = query.Where(row => row.Field<int>("ParentMenuId") == parentMenuId); foreach (var row in querySubMenuItem) { ToolStripMenuItem subMenuItem = (ToolStripMenuItem)menu.DropDownItems.Add(row.Field<string>("MenuText")); subMenuItem.Tag = row.Field<string>("Category"); CreateSubMenu(query, subMenuItem, row.Field<int>("MenuId"), level + 1); } }