Iram Hamdani

Iram Hamdani

  • 1.6k
  • 94
  • 401

I am Trying to create structure based on parent child

Jul 5 2022 10:08 AM

Wants to create <ul> <li> based structure  by using table based on parent child roots upto n levels .. facing an issu

  • TECH
    • Company Maintenance
    • Employees
    • Human Resources
  • XRP
    • Company Maintenance
    • Employees
    • Human Resources

write  below code but facing an issue:

  using (DatabaseContext ctx = new DatabaseContext())
      {
        var Alllocations = ctx.GetAllLocations().Where(x => x.ClientId == clientno);
        int count = Alllocations.Count();
        foreach (var location in Alllocations)
        {
          int LevelCount = 0;
          string[] leveld;
          LevelCount = location.LevelID.Split('>').Length;
           leveld=  location.LevelID.Split('>');
          string max=string.Empty;
          int level = 0;
          
          for (int i = 0; i <=LevelCount; i++)
          {
            if (location.ParentID == null&& LevelCount==1)
            {
              Option += "<ul>";
            }
            max = leveld.Max();
            level++;
          }
          int n = 0;
          while (n != level)
          {
            if (max != string.Empty && n==level)
            {
              Option += "</ul>";
              break;
            }
            n++;
          }
          

          Option += "<li>"+ "<a>"+location.Self_Description + "</a>" + "</li>";
            //Option += "<li style=color:" + Color + " class='Level_" + LevelCount + ">" + Space + location.Self_Description + "</li>";
          }
        return (Option);
      }
    }