0
votes

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

1
Post your markup and code behind. - Juliet
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SumooHAgentDBConnectionString %>" SelectCommand="SELECT DISTINCT [MachineGroupName], [MachineGroupID] FROM [MachineGroups]"> </asp:SqlDataSource> <asp:TreeView ID="TreeView2" runat="server" ontreenodepopulate="TreeView2_TreeNodePopulate"> <Nodes> <asp:TreeNode PopulateOnDemand="True" Text="Machine Group" Value="Machine Group" NavigateUrl="~/Gridviewpage.aspx"></asp:TreeNode> </Nodes> </asp:TreeView> - user175084
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
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
Can edit the question and add your code? It's tough to read when it's run together in the comments. - SqlRyan

1 Answers

0
votes

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";