473,385 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How can i add parent,child,sub child nodes on treeview in asp.net?

In the below code was executed succesful but it doesn't added child and subnodes plse send me code how can i add child nodes and subchild nodes in treeview aswellas in to database ,pleas help me
Expand|Select|Wrap|Line Numbers
  1. public void treeviewcontrol()
  2.     {
  3.         //con.Open();
  4.         TreeView1.Nodes.Clear();
  5.         SqlCommand cmd=new SqlCommand("select groups from treeview",con);
  6.         SqlDataAdapter da = new SqlDataAdapter(cmd);
  7.         DataSet ds = new DataSet();
  8.         da.Fill(ds);
  9.         con.Open();
  10.         foreach (DataRow dr in ds.Tables[0].Rows)
  11.         {
  12.             TreeNode group = new TreeNode();
  13.             group.Text = dr["groups"].ToString();
  14.             group.Value = dr["groups"].ToString();
  15.             //TreeView1.Nodes.Add(group);
  16.  
  17.             SqlCommand cmd1 = new SqlCommand("select subgroup from treeview where groups='" + group.Value+"'",con );
  18.             SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
  19.             DataSet ds1 = new DataSet();
  20.  
  21.             da1.Fill(ds1);
  22.  
  23.             foreach (DataRow dr1 in ds1.Tables[0].Rows)
  24.             {
  25.                 TreeNode subgroup = new TreeNode();
  26.                 subgroup.Text = dr1["subgroup"].ToString();
  27.                 subgroup.Value = dr1["subgroup"].ToString();
  28.                 group.ChildNodes.Add(subgroup);
  29.  
  30.                 SqlCommand cmd2 = new SqlCommand("select item from treeview where groups='" + group.Value+"'",con );
  31.                 SqlDataAdapter da2 = new SqlDataAdapter(cmd2 );
  32.                 DataSet ds2 = new DataSet();
  33.                 da2.Fill(ds2);
  34.                 foreach (DataRow dr2 in ds2.Tables[0].Rows) 
  35.                 {
  36.                     TreeNode item = new TreeNode();
  37.                     item.Text = dr2["item"].ToString();
  38.                     item.Value = dr2["item"].ToString();
  39.                   subgroup.ChildNodes.Add(item );
  40.                  item.CollapseAll();
  41.  
  42.                 } 
  43.             }
  44.             TreeView1.Nodes.Add(group);
  45.         }
  46.  
  47.  
  48.         con.Close();
  49.  
  50.         TreeView1.ExpandAll();
May 5 '11 #1
0 1540

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: maricel | last post by:
Is there a way to list (using db2 command or catalogs) to list hierarchy of table parent & child relationship: 1) A list that shows which table should be deleted first,second,third... 2) A list...
5
by: B-Dog | last post by:
I want to be able to detect if a user has selected a parent or child node in a treeview and depending on which is clicked act accordingly based on the tag. I can get the values but don't know if...
2
by: Thelma Lubkin | last post by:
My ColorSet building form/subform now works beautifully, thanks to the help that I've gotten from people in this group. The working form displays the parent ColorSet record with the child records...
1
by: kunju | last post by:
Hi, I want to import data to a parent and child table from two different csv files. Csv file for the parent table have got the primary key(integer) field and child have the forien key . My problem...
4
by: psbasha | last post by:
I would like to create a Parent and Child Dialog in Tkinter. Parent Dialog will be having have the Combo Box with Geometry Selection Parent Dialog : ------------------- - Point - Line -...
2
by: ChaoticDALO | last post by:
Hello, I am wondering if this is possible. If I have a parent class and a child that inherits the parent, the child can access a parents member function right? Well let's say we are in the parent...
1
by: Bhishm | last post by:
Hi, I have a window (192.168.1.223/test.ph) in which one iframe continuously runs. I open another window from that window (192.168.1.223/test1.php) which also runs an iframe continuously. ...
0
by: =?Utf-8?B?ZGV0cml1czY3?= | last post by:
I'm having a problem in C# (visual studio 2005) concerning minimising parent and child forms. I need to be able to handle the minimise event for the child and tell the parent to minimise at the...
4
by: jewel87 | last post by:
Hi everyone! I'm writing some code in C under UNIX, which should give some output like this: PARENT: pid = 10063 CHILD: my pid = 10064 CHILD: my parent's pid = 10063 CHILD: Sleeping... PARENT:...
1
by: Sep410 | last post by:
Private Sub frmSearch_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim sql1 As String Dim sql2 As String Dim da1 As SqlDataAdapter ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.