Populating TreeView Control With Database

I have recently published an article on GridViewGuy on how to populate the TreeView control using the database. The article demonstrate the solution using entity classes. Here is a small code snippet from the article.


// This method is used to populate the TreeView Control 
    
private void PopulateTreeViewControl(List<Category> categoryList)
    {
        TreeNode parentNode = 
null

        
foreach (Category category in categoryList)
        {
            parentNode = 
new TreeNode(category.CategoryName,
            category.CategoryID.ToString());
            
            
foreach (Product product in category.ProductList)
            {
                TreeNode childNode = 
new TreeNode(product.ProductName,
                product.ProductID.ToString());
             
                parentNode.ChildNodes.Add(childNode); 
            }

                    
            parentNode.Collapse(); 
            
// Show all checkboxes 
            
tvCategories.ShowCheckBoxes = TreeNodeTypes.All; 
            tvCategories.Nodes.Add(parentNode); 
        }
    }

For the complete article please visit the following link:

Populating TreeView Using Database

powered by IMHO 1.3

Print | posted @ Wednesday, June 28, 2006 8:51 PM

Twitter