Hi, all
am using asp.net 2.0, c#
i have a tree view control
from two tables i have to add nodes dynamically
i hav category(cat_id ,cat_name),
sub category(sub_ca t_id,cat_id,sub _cat_name) tables
under category node i have to fill subcategory names as child node - con.Open()
-
cmd = New SqlCommand("select cat_id,cat_name from tbl_category order by cat_name", con)
-
dr = cmd.ExecuteReader()
-
While dr.Read()
-
cat = New TreeNode()
-
cat.Text = dr("cat_name").ToString
-
cat.Value = dr("cat_id").ToString
-
TreeView2.Nodes.Add(cat)
-
End While
-
-
dr.Close()
-
con.Close()
using above code i filled parent nodes
how to get child nodes?
please help me
Thankyou
2 41356
Just Copy and paste the below code it will dynamically display the parent node and child nodes, datas will be fetched from the database. You set the tables correctly, hope u add primary key in parent table and foreign key in child table. I added two textbox to enter parent node and child node , users can enter as many child node to a particular parent node separated by commas . and it will display the newly added parent and child node when they click the add button. - public partial class NewTreeView : System.Web.UI.Page
-
{
-
SqlConnection con = new SqlConnection("SERVER = \\SQLEXPRESS; DATABASE = db; UID = usr ; PwD = pwd ;");
-
int userid = 0;
-
string childItem = "";
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
if (!IsPostBack)
-
{
-
FillTreeView();
-
}
-
}
-
private void FillTreeView()
-
{
-
try
-
{
-
con.Open();
-
{
-
SqlCommand SqlCmd = new SqlCommand("Select userid ,username from sampledb", con);
-
SqlDataReader Sdr = SqlCmd.ExecuteReader();
-
SqlCmd.Dispose();
-
string[,] ParentNode = new string[100, 2];
-
int count = 0;
-
-
while (Sdr.Read())
-
{
-
ParentNode[count, 0] = Sdr.GetValue(Sdr.GetOrdinal("USERId")).ToString();
-
ParentNode[count++, 1] = Sdr.GetValue(Sdr.GetOrdinal("USERNAME")).ToString();
-
}
-
Sdr.Close();
-
for (int loop = 0; loop < count; loop++)
-
{
-
TreeNode root = new TreeNode();
-
root.Text = ParentNode[loop, 1];
-
root.Target = "_blank";
-
root.NavigateUrl = "Tree1.aspx";
-
-
SqlCommand Module_SqlCmd = new SqlCommand("Select usrid , childname from child where usrid =" + ParentNode[loop, 0], con);
-
SqlDataReader Module_Sdr = Module_SqlCmd.ExecuteReader();
-
while (Module_Sdr.Read())
-
{
-
//siva To Add children module to the root node
-
TreeNode child = new TreeNode();
-
child.Text = Module_Sdr.GetValue(Module_Sdr.GetOrdinal("childname")).ToString();
-
child.Target = "_blank";
-
child.NavigateUrl = "Tree2.aspx";
-
root.ChildNodes.Add(child);
-
}
-
Module_Sdr.Close();
-
TreeView1.Nodes.Add(root);
-
TreeView1.CollapseAll();
-
-
}
-
-
}
-
-
}
-
catch
-
{
-
}
-
finally
-
{
-
con.Close();
-
}
-
}
-
-
protected void Button2_Click(object sender, EventArgs e)
-
{
-
con.Open();
-
{
-
SqlCommand SqlCmd = new SqlCommand("insert into sampledb(USERNAME) values('"+TextBox1.Text+"')", con);
-
SqlCmd.ExecuteNonQuery();
-
SqlCommand SqlCmd1 = new SqlCommand("SELECT TOP 1 USERID FROM sampledb ORDER BY USERID DESC", con);
-
SqlDataReader dr = SqlCmd1.ExecuteReader();
-
while (dr.Read())
-
{
-
userid = Convert.ToInt32(dr["USERID"].ToString());
-
}
-
dr.Close();
-
string childNode = TextBox2.Text;
-
string[] childs = new string[3];
-
if (childNode.Contains(","))
-
{
-
childs = childNode.Split(',');
-
for (int i = 0; i < childs.Length; i++)
-
{
-
childItem = childs[i].ToString();
-
SqlCommand SqlCmd2 = new SqlCommand("insert into child(usrid,childname) values('" + userid + "','" + childItem.ToString() + "')", con);
-
SqlCmd2.ExecuteNonQuery();
-
}
-
-
}
-
else
-
{
-
SqlCommand SqlCmd3 = new SqlCommand("insert into child(usrid,childname) values('" + userid + "','" + TextBox2.Text + "')", con);
-
SqlCmd3.ExecuteNonQuery();
-
}
-
}
-
con.Close();
-
Response.Redirect("newtreeview.aspx");
-
}
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: imani_technology_spam |
last post by:
We need to present hierarchical data on a web page, the same way the
tree view shows files in Windows Explorer. Here's the catch: that
tree view needs to be bound to a SQL Server database. How can this be
done?
|
by: Dino L. |
last post by:
I am putting data from DataTable to treeView
foreach( DataRow aRow in aTable.Rows)
{
TreeNode tnode = new TreeNode(aRow.ToString() + aRow.ToString() +
" " + aRow.ToString());
treeView1.Nodes.Add(tnode);
//till here code works fine
//now I wanna add child nodes for last inserted node
foreach( DataRow GrupaRow in TabelaGrupe.Rows)
|
by: Brian Henry |
last post by:
If i already have a tree view created, and want to add another new node to
it, how would i do so? Is there a way to throught tags or anything? like i
have this
RootNode
|
+-- Child 1
+-- Child 2
and i want to add a child node to child 1 how would i refrence it and add a
|
by: Kevin Lippiatt |
last post by:
Can anyone advise me on how well the windows .net tree view control performs
when loaded with large numbers of nodes.
I'm intersted in how it might perform when used with possibly millions of
nodes.
At what point will the control be 'over-stressed'?
|
by: rinishrk |
last post by:
Hi,
I have a web application that contains subfolders Admin and User with
related webpages inside them. Within the Admin folder I have a page
containing a Tree View Control.I want this tree view to have nodes for
all pages in the website. However it seems that I cannot create child
nodes within this tree view for pages that exist outside the Admin
folder.(i.e.pags within the User folder or the Root folder ).It gives
me an errors stating...
| |
by: teju |
last post by:
Hi all,
I am trying to populate tree view from the database. Till two levels i can populate it fine but when it reaches third level it doesn't expand. Below is the code, it has been taken from the reference of micrososft
Sub PopulateNode(ByVal sender As Object, ByVal e As TreeNodeEventArgs)
' Call the appropriate method to populate a node at a particular level.
If e.Node.ChildNodes.Count = 0 Then
Select Case...
|
by: Bob |
last post by:
Hi,
I would to have a tree view control with check boxes in which the
parent and child nodes interacts, in the way that you normally see
this occuring. Checking the parent node automatically checks all its
children node. Conversely, if one of the child nodes is unchecked,
the parent node unchecks. Is there a property of the treeview that
will automatically do this for me or do I need to roll my own?
Thanks,
Bob
|
by: jakki |
last post by:
i want to populate a data from a data base..
i wrote a code for webapplication aspx.cs.. which is perfectly work's
code is
protected void Page_Load(object sender, EventArgs e)
{
|
by: Developer111 |
last post by:
I am developing a tree view like application using HTML. The problem is that although I am using the same CSS styles for both parent and child node at sub level, but there is an uneven line spacing between parent and child nodes, when parent node in collapsed i.e.
EXPANDED TREE STATE:-
-Parent Node
-Sub-Parent Node.
-Child 1 of Sub-Parent Node.
. Desc of Child 1
-Child 2 of Sub-Parent Node.
. Desc of Child 2
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |