private void AddChildItems(DataTable table, string Value, ClsSubMenus SubMenu) { DataView viewItem = new DataView(table); viewItem.RowFilter = "menu_parent_id=" + Value; foreach (DataRowView childView in viewItem) { string value = childView["menu_id"].ToString(); SubMenu.Url = SubMenu.Url + "$" + childView["menu_url"].ToString().Replace("~/View/", "").Replace("View/", ""); SubMenu.Text = SubMenu.Text + "$" + childView["menu_name"].ToString(); AddChildItems(table, value, SubMenu); } }
private void GetMenuData() { string roll = Session["RollID"].ToString(); string[] a = roll.Split(','); string subquery = ""; for (int i = 0; i < a.Length; i++) { if (a[i].ToString().Trim() != "") { subquery = subquery + "Or (Assigned_roll like '%," + a[i] + ",%' or Assigned_roll like '" + a[i] + ",%' or Assigned_roll like '" + a[i] + "%' or Assigned_roll like '%," + a[i] + "' )"; } } DataTable table = new DataTable(); string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["connstr"].ConnectionString; SqlConnection conn = new SqlConnection(strCon); string sql = "select menu_id, menu_name, menu_parent_id, menu_url,status from menuMaster where status =1 and IsVisible=1 and ( (menu_parent_id is NULL) " + subquery + ") order by orderby"; if (!(sql.Contains("update") || sql.Contains("delete"))) { SqlCommand cmd = new SqlCommand(sql, conn); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(table); DataView view = new DataView(table); view.RowFilter = "menu_parent_id is NULL"; foreach (DataRowView row in view) { ClsHeader Header = new ClsHeader(); Header.Url = row["menu_url"].ToString().Replace("~/View/", "").Replace("View/", ""); Header.Text = row["menu_name"].ToString(); HeaderAndSubMenu.LstOfHeader.Add(Header); ClsSubMenus SubMenu = new ClsSubMenus(); AddChildItems(table, row["menu_id"].ToString(), SubMenu); HeaderAndSubMenu.LstOfSubMenus.Add(SubMenu); } } }