Data Hierarchy - TreeView Representation RRS feed

  • Question

  • User-698989805 posted

    Hello friends! I am trying to create a TreeView that should be expanded to 4th level depending upon a condition using ASP.NET Web Form. I am able to expand it up to 3rd level data hierarchy. Now the issue is there is a column, you can say, it's like a status column. If the status column is false, then it should expand through the 4th level and show a message like inactive or something from database. This is what I've done so far:

    The red-highlighted shows the third level hierarchy. Let me clarify first, I am not posting the tables here else it would become huge here. I am sharing the class and the LINQ that I've written so far. Three tables are joined and in the third, I've the status column. The below is the class:

    public class EquipaViewModel
       public string CLIENTENOME { get; set; } //GRUPO HIDROPRESSOR 1
       public string LOCAL { get; set; } //A1
       public string MAQ_NOME { get; set; } //ESTACIONAMENTO-4
       public boolean OBS { get; set; } //The status column

    So my condition is if the status is false, then for the third hierarchy, there should be an option to expand to the forth hierarchy that should show a message inactive. If true, then no option for the forth hierarchy but both should be displayed in the TreeView. In my case, I am only getting the hierarchy for the false status right now, more specifically for one condition. This is what I've tried so far using a Label and concatenation:

    var result = (from c in db2.A1_LOCAISMAQ
                  join d in db2.A2_MAQUINAS on c.LOCALMAQ_INC equals d.LOCALMAQ_INC
                  join f in db2.A3_PONTO_LUB on d.MAQUINAS_NINC equals f.MAQUINAS_NINC
                  select new EquipaViewModel { OBS = f.MAQ_ATIVA, CLIENTENOME = f.PONTO_DESIGNA, LOCAL = c.LOCAL, MAQ_NOME = d.MAQ_NOME }).ToList();
     foreach (var item in result.GroupBy(p => p.LOCAL))
       lblList.Text  += "<li class='level1'>" + " " + item.Key + "<ul>";
       foreach (var item2 in result.Where(p => p.LOCAL == item.Key).GroupBy(m => m.MAQ_NOME, (key, c) => c.FirstOrDefault()))
          lblList.Text += "<li class='level2'>" + " " + item2.MAQ_NOME + "<ul>";
          foreach (var item3 in result.Where(p => p.MAQ_NOME == item2.MAQ_NOME).GroupBy(m => m.CLIENTENOME, (key, c) => c.FirstOrDefault()))
             lblList.Text += "<li class='level3'>" + " " + item3.CLIENTENOME + "<ul>";
              **if (item3.OBS == true)
                lblList.Text += "<li><img src='ProjectImages/active.png' height='20px' width='20px' />" + item3.CLIENTENOME + "</li>";
                foreach (var item4 in result.Where(p => p.CLIENTENOME == item3.CLIENTENOME).GroupBy(m => m.OBS, (key, c) => c.FirstOrDefault()))
                     lblList.Text += "<li><img src='ProjectImages/inactive.png' height='20px' width='20px' /><a href='#' id='" + "Correcto" + "'>" + " " + "inactive" + "</a></li>";
        lblList.Text += "</ul></li>";
    lblList.Text  +=  "</ul></li>";

    I am guessing, I am doing wrong in the level 3 section. When it'll come to level three, then it should decide from the statement whether there should be option for the forth hierarchy. Any suggestion or idea would be highly appreciated - Thanks.

    Monday, January 15, 2018 6:45 PM


  • User-707554951 posted

    Hi TechView

    From your description and code your provided.

    It is hard for us to find your problem.

    So, I suggest you could set break point on your code to debug step by step.

    Best regards


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 16, 2018 6:44 AM