I have a TreeView component, and a structure in the database that already has in the directories subdirectories table. has a field called directive_parent_guid, if it is null it is because it is root, if not, it is some Id of another directory. So I have the following structure:
Method that returns directories: expecting a parameter that will list only directories with parent guid equal to the last string:
internal List<Diretorio> GetSubDiretorio(String termo)
{
using (var ctx = new TESTEntities())
{
var diretorios = (
from dir in ctx.DIRETORIO
where dir.DIRETORIO_PARENT_GUID == termo
select new Diretorio()
{
DIRETORIO_GUID = dir.DIRETORIO_GUID,
XDIRETORIO = dir.XDIRETORIO,
REFERENCIA = dir.REFERENCIA
}
).ToList();
return diretorios;
}
}
Treeview padding I've tried:
public void CriarTreeView()
{
var raiz = DiretorioController.GetInstance().GetSubDiretorio("");
foreach (var diretorio in raiz )
{
node = new TreeNode(diretorio.XDIRETORIO);
node.ImageUrl = "~/asstes/img/directory.png";
TreeView1.Nodes.Add(node);
foreach (var subDiretorio in DiretorioController.GetInstance().GetSubDiretorio())
{
TreeNode nodeSub = new TreeNode(subDiretorio.XDIRETORIO);
nodeSub.ImageUrl = "~/asstes/img/directory.png";
node.ChildNodes.Add(nodeSub);
}
}
}
In this way it works directories and subdirectories, but it gets manual, if I create a directory within a subdirectory it does not list, I have not been able to apply the correct logic yet. How would you list the subdirectories correctly?