Click here to Skip to main content
12,243,729 members (37,789 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
hi brothers and sisters i am beginner in this field so please help me i am already binded the database to the tree view but i Want to clear the tree view and bind the same database another once how can i do please help me
i use this but it doesn't work...

TreeView1.Attributes.Clear();


code is

public void loadtreeview(string connection)
        {
            FirstMiniProject.FirstMiniProject f = new FirstMiniProject.FirstMiniProject(connection);
            string sql = string.Format("SELECT name FROM sys.databases WHERE name NOT IN ('master', 'tempdb', 'model', 'msdb')");
            DataTable tab = new DataTable();
            tab = f.loadtable(sql);
            for (int i = 0; i < tab.Rows.Count; i++)
            {
                string root = tab.Rows[i]["name"].ToString();
                TreeView1.Nodes.Add(new TreeNode(root));
                string sql1 = string.Format("USE {0} SELECT name FROM sys.Tables", root);
                DataTable tab1 = new DataTable();
                tab1 = f.loadtable(sql1);
                for (int j = 0; j < tab1.Rows.Count; j++)
                {
                    string child = tab1.Rows[j]["name"].ToString();
                    TreeView1.Nodes[i].ChildNodes.Add(new TreeNode(child));
                }
 
            }
        }
i want to clear the tree view after that i will call this function once again to bind;;;;
Posted 14-Dec-12 19:27pm
Edited 14-Dec-12 19:56pm
v3
Comments
Krunal Rohit 15-Dec-12 0:45am
   
Elaborate your question... Provide your code...
-Krunal R.
Member 9644686 15-Dec-12 0:53am
   
i sended...
Krunal Rohit 15-Dec-12 0:56am
   
Its sent, not sended...
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

to bind data go through this article

Data Binding TreeView in C#[^]

and to clear
TreeView1.Nodes.Clear()
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 15 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100