<asp:TreeView ID="TreeView1" runat="server" ImageSet="XPFileExplorer" NodeIndent="15">
<HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
<NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black" HorizontalPadding="2px"
NodeSpacing="0px" VerticalPadding="2px"></NodeStyle>
<ParentNodeStyle Font-Bold="False" />
<SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" HorizontalPadding="0px"
VerticalPadding="0px" />
</asp:TreeView>
{
if (!this.IsPostBack)
{
List<BE_Account> lst = new DAL_Account().GETRecord();
List<BE_Account> lstAC = lst;
AddTopTreeViewNodes(lst);
}
}
private void AddTopTreeViewNodes(List<BE_Account> List)
{
List<BE_Account> Listss = List.Where(Id => Id.ControlAccountID == 0).ToList();
foreach (BE_Account Item in Listss)
{
TreeNode newNode = new TreeNode(Item.Description, Item.AccountID.ToString());
TreeView1.Nodes.Add(newNode);
AddChildTreeViewNodes(List, newNode);
newNode.CollapseAll();
}
}
private void AddChildTreeViewNodes(List<BE_Account> List, TreeNode parentTreeViewNode)
{
List<BE_Account> Lsts = List.Where(Id => Id.ControlAccountID == Convert.ToInt32(parentTreeViewNode.Value)).ToList();
foreach (BE_Account Item in Lsts)
{
TreeNode newNode = new TreeNode(Item.Description, Item.AccountID.ToString());
parentTreeViewNode.ChildNodes.Add(newNode);
AddChildTreeViewNodes(List, newNode);
}
}
No comments :
Post a Comment