0

have a treeview control in ASP.NET and C#.

Root node (This is fixed)

---Parent Node 1 ( Parent node and child are populated from the database directly. )

----Child node1

----Child node2

---Parent node 2

Now When a value is added to a database it get added in the treeview. I cannot get a way to select the parent and child node and make it perform a function like go to another page or something...

I have the code to retrieve values from the database and display on the treenode dynamically. Just the selection is a problem.

If there is a tutorial of any other information please let me know

Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191
user175084
  • 4,550
  • 28
  • 114
  • 169
  • Post your markup and code behind. – Juliet Sep 17 '09 at 17:08
  • protected void TreeView2_TreeNodePopulate(object sender, TreeNodeEventArgs e) { if (e.Node.ChildNodes.Count == 0) { switch (e.Node.Depth) { case 0: PopulateMachineGroups(e.Node); break; case 1: PopulateMachines(e.Node); break; – user175084 Sep 17 '09 at 17:17
  • protected void PopulateMachines(TreeNode node) { SqlCommand sqlQuery = new SqlCommand(); sqlQuery.CommandText = "Select MachineName From Machines " +" Where MachineGroupID = @machinegrpid"; sqlQuery.Parameters.Add("@machinegrpid", SqlDbType.Int).Value=node.Value; DataSet ResultSet = RunQuery(sqlQuery); if (ResultSet.Tables.Count > 0) { foreach (DataRow row in ResultSet.Tables[0].Rows) { TreeNode NewNode = new TreeNode(row["MachineName"].ToString()); NewNode.PopulateOnDemand = false; NewNode.SelectAction =TreeNodeSelectAction.None; node.ChildNodes.Add(NewNode); } } } – user175084 Sep 17 '09 at 17:22
  • 1st box is the aspx page 2nd box is how i switch 3rd box is to populate the tree so the tree should look like machinegroup (root) --machines1 (parent) ----pc1 (child) ----pc2 where the parent and child are in two different tables – user175084 Sep 17 '09 at 17:26
  • 1
    Can edit the question and add your code? It's tough to read when it's run together in the comments. – SqlRyan Sep 18 '09 at 04:48
  • what you want acheive in the selection? do you want to show checkboxes along with the node? – Muhammad Akhtar Sep 18 '09 at 05:41

1 Answers1

0

I think what you need to do is to go to another page where you adding your new treenode, you need to set navigateURL property

NewNode.NavigateUrl = "yourURL";
Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191
  • this worked if you are sending all the child nodes or parent nodes to the respective pages but i wanted to know which node is getting selected also. I was able to do this by sending the value in the navigation URl itself : NewNode.NavigateUrl = "~/WebForm4.aspx?node=" + NewNode.Text; then you have to add a query string at the page you navigate to, in order to vetch the value you just passed. Thanks. – user175084 Sep 18 '09 at 15:54