public class Node {
public int id { get; set; }
public string name { get; set; }
public int prntid { get; set; }
public List<Node> children { get; set; }
}
List<Node> parentsList = new List<Node>();
TestEntities db = new TestEntities();
GetNodeTreeviewDetails();
public List<Node> GetNodeTreeviewDetails()
{
try
{
parentsList = (from row in db.Tbl_Node.ToList()
where row.PARENT_ID == 0
select new Node
{
id = row.ID,
name = row.NODE_ID,
prntid = row.PARENT_ID
}).ToList();
GetChildNodeTreeviewDetails(parentsList);
return parentsList;
}
catch (Exception ee)
{
throw ee;
}
}
public void GetChildNodeTreeviewDetails(List<Node> nodesList)
{
foreach (Node childNode in nodesList)
{
List<Node> childNodesList = (from row in db.Tbl_Node.ToList()
where row.PARENT_ID == childNode.id
select new Node
{
id = row.ID,
name = row.NODE_ID,
prntid = row.PARENT_ID
}).ToList();
childNode.children = childNodesList;
GetChildNodeTreeviewDetails(childNodesList);
}
}
public int id { get; set; }
public string name { get; set; }
public int prntid { get; set; }
public List<Node> children { get; set; }
}
List<Node> parentsList = new List<Node>();
TestEntities db = new TestEntities();
GetNodeTreeviewDetails();
public List<Node> GetNodeTreeviewDetails()
{
try
{
parentsList = (from row in db.Tbl_Node.ToList()
where row.PARENT_ID == 0
select new Node
{
id = row.ID,
name = row.NODE_ID,
prntid = row.PARENT_ID
}).ToList();
GetChildNodeTreeviewDetails(parentsList);
return parentsList;
}
catch (Exception ee)
{
throw ee;
}
}
public void GetChildNodeTreeviewDetails(List<Node> nodesList)
{
foreach (Node childNode in nodesList)
{
List<Node> childNodesList = (from row in db.Tbl_Node.ToList()
where row.PARENT_ID == childNode.id
select new Node
{
id = row.ID,
name = row.NODE_ID,
prntid = row.PARENT_ID
}).ToList();
childNode.children = childNodesList;
GetChildNodeTreeviewDetails(childNodesList);
}
}