473,779 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

populating treeview

Hi all,

I have a dataset that contains following records:

id ref_id level
--------------------------------------
A - 0
A1 A 1
A2 A 1
A3 A 1
A11 A1 2
A12 A1 2
A21 A2 2
A31 A3 2
A211 A21 3

The column 'ref_id' is supposed to be the parent/referrer of column 'id'
That means:
A refers A1,A2 and A3
A1 refers A11,A12
and so on.

What I want to achieve is to present the above dataset using a treeview in
an ASP.NET 2.0 (VB) page, so it will displays like this:

[+] A
[+] A1
A11
A12
[+] A2
[+] A21
A211
[+] A3
A31

Can somebody please show me how to do this?

Many thanks in advance,
Mike

May 31 '06 #1
2 1356
I would suggest creating possibly a class and two methods.

The class would basically represent each of your nodes we can call it
HtmlTreeNode probably with a ChildNodes property which holds a
collection of other HtmlTreeNodes and a ToHtml() method to create the
html representation of the contained data.

This could look like:

public class HtmlTreeNode
{
HtmlTreeNode[] _childNodes;
public HtmlTreeNode()
{
_childNodes = new HtmlTreeNode[];
}
public HtmlTreeNode[] ChildNodes
{
get { return _childNodes; }
set { _childNodes = value; }
}
public string ToHtml()
{
// This would create the Html output of this node, and its ChildNodes
}
}

Then for the other methods (which you could build into the class if you
want) - the first method would be something like:

HtmlTreeNode[] GetRootNodes()
{
//...
}

The second would be:

HtmlTreeNode[] GetChildNodes()
{
//...
}

The GetChildNodes() could recursively call itself to get all of the
subsequent children all the way down.

Sorry that this is in C# but you should be able to get the basic idea I
hope. If not let me know and I can try to redo it in VB, I just think
faster in C# since that's about all I use these days. =)

Hope that helps.

Mike wrote:
Hi all,

I have a dataset that contains following records:

id ref_id level
--------------------------------------
A - 0
A1 A 1
A2 A 1
A3 A 1
A11 A1 2
A12 A1 2
A21 A2 2
A31 A3 2
A211 A21 3

The column 'ref_id' is supposed to be the parent/referrer of column 'id'
That means:
A refers A1,A2 and A3
A1 refers A11,A12
and so on.

What I want to achieve is to present the above dataset using a treeview in
an ASP.NET 2.0 (VB) page, so it will displays like this:

[+] A
[+] A1
A11
A12
[+] A2
[+] A21
A211
[+] A3
A31

Can somebody please show me how to do this?

Many thanks in advance,
Mike

------=_NextPart_000_ 0071_01C684EC.1 E0F8640
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-Google-AttachSize: 2497

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2873" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff >
<DIV>Hi all,<BR><BR>I have a dataset that contains following
records:<BR><BR >id&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp;&nbsp;
ref_id&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;
level<BR>--------------------------------------<BR>A&nbsp;&nbs p;&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;
-&nbsp;&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp;&nbsp;
0<BR>A1&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;
A&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;
1<BR>A2&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;
A&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;
1<BR>A3&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;
A&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;
1<BR>A11&nbsp;& nbsp;&nbsp;&nbs p;
A1&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;
2<BR>A12&nbsp;& nbsp;&nbsp;&nbs p;
A1&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;
2<BR>A21&nbsp;& nbsp;&nbsp;&nbs p;
A2&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;
2<BR>A31&nbsp;& nbsp;&nbsp;&nbs p;
A3&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;
2<BR>A211&nbsp; &nbsp;
A21&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp; 3<BR><BR>The
column 'ref_id' is supposed to be the parent/referrer of column 'id'<BR>That
means:<BR>A refers A1,A2 and A3<BR>A1 refers A11,A12<BR>and so on.<BR><BR>What I
want to achieve is to present the above dataset using a treeview in<BR>an
ASP.NET 2.0 (VB) page, so it will displays like this:<BR><BR>[+]
A<BR>&nbsp;&nbs p;&nbsp; [+]
A1<BR>&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp;&nbsp;
A11<BR>&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;
A12<BR>&nbsp;&n bsp;&nbsp; [+]
A2<BR>&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp; [+]
A21<BR>&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;
A211<BR>&nbsp;& nbsp;&nbsp; [+]
A3<BR>&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp; A31<BR><BR>Can somebody
please show me how to do this?<BR><BR>Ma ny thanks in
advance,<BR>Mik e<BR><BR><BR></DIV></BODY></HTML>

------=_NextPart_000_ 0071_01C684EC.1 E0F8640--


May 31 '06 #2
Hi there,

Thanks for the suggestion. I'll try it out, and come back to you with the
results.
Anyway, thanks a lot. I appreciate it.

Regards,
Mike

"gmiley" <gm****@gmail.c om> wrote in message
news:11******** *************@u 72g2000cwu.goog legroups.com...
I would suggest creating possibly a class and two methods.

The class would basically represent each of your nodes we can call it
HtmlTreeNode probably with a ChildNodes property which holds a
collection of other HtmlTreeNodes and a ToHtml() method to create the
html representation of the contained data.

This could look like:

public class HtmlTreeNode
{
HtmlTreeNode[] _childNodes;
public HtmlTreeNode()
{
_childNodes = new HtmlTreeNode[];
}
public HtmlTreeNode[] ChildNodes
{
get { return _childNodes; }
set { _childNodes = value; }
}
public string ToHtml()
{
// This would create the Html output of this node, and its ChildNodes
}
}

Then for the other methods (which you could build into the class if you
want) - the first method would be something like:

HtmlTreeNode[] GetRootNodes()
{
//...
}

The second would be:

HtmlTreeNode[] GetChildNodes()
{
//...
}

The GetChildNodes() could recursively call itself to get all of the
subsequent children all the way down.

Sorry that this is in C# but you should be able to get the basic idea I
hope. If not let me know and I can try to redo it in VB, I just think
faster in C# since that's about all I use these days. =)

Hope that helps.

Mike wrote:
Hi all,

I have a dataset that contains following records:

id ref_id level
--------------------------------------
A - 0
A1 A 1
A2 A 1
A3 A 1
A11 A1 2
A12 A1 2
A21 A2 2
A31 A3 2
A211 A21 3

The column 'ref_id' is supposed to be the parent/referrer of column 'id'
That means:
A refers A1,A2 and A3
A1 refers A11,A12
and so on.

What I want to achieve is to present the above dataset using a treeview
in
an ASP.NET 2.0 (VB) page, so it will displays like this:

[+] A
[+] A1
A11
A12
[+] A2
[+] A21
A211
[+] A3
A31

Can somebody please show me how to do this?

Many thanks in advance,
Mike

------=_NextPart_000_ 0071_01C684EC.1 E0F8640
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-Google-AttachSize: 2497

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2873" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff >
<DIV>Hi all,<BR><BR>I have a dataset that contains following
records:<BR><BR >id&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp;&nbsp;
ref_id&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;
level<BR>--------------------------------------<BR>A&nbsp;&nbs p;&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;
-&nbsp;&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp;&nbsp;
0<BR>A1&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;
A&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;
1<BR>A2&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;
A&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;
1<BR>A3&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;
A&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;
1<BR>A11&nbsp;& nbsp;&nbsp;&nbs p;
A1&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;
2<BR>A12&nbsp;& nbsp;&nbsp;&nbs p;
A1&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;
2<BR>A21&nbsp;& nbsp;&nbsp;&nbs p;
A2&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;
2<BR>A31&nbsp;& nbsp;&nbsp;&nbs p;
A3&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;
2<BR>A211&nbsp; &nbsp;
A21&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;
3<BR><BR>The
column 'ref_id' is supposed to be the parent/referrer of column
'id'<BR>That
means:<BR>A refers A1,A2 and A3<BR>A1 refers A11,A12<BR>and so
on.<BR><BR>What I
want to achieve is to present the above dataset using a treeview in<BR>an
ASP.NET 2.0 (VB) page, so it will displays like this:<BR><BR>[+]
A<BR>&nbsp;&nbs p;&nbsp; [+]
A1<BR>&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp;&nbsp;
A11<BR>&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;
A12<BR>&nbsp;&n bsp;&nbsp; [+]
A2<BR>&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp; [+]
A21<BR>&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;
A211<BR>&nbsp;& nbsp;&nbsp; [+]
A3<BR>&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp; A31<BR><BR>Can
somebody
please show me how to do this?<BR><BR>Ma ny thanks in
advance,<BR>Mik e<BR><BR><BR></DIV></BODY></HTML>

------=_NextPart_000_ 0071_01C684EC.1 E0F8640--

Jun 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6104
by: Karuppasamy | last post by:
Hi I want to populate all the files and folders of System in a Treeview control like Windows Explorer. I try this using File System Objects. But sometimes I am getting an error like 'Access Denied". Why am I getting an error like this? How to populate the TreeView with Folders and files of the System?
0
2092
by: imassadpk | last post by:
Hi all, Apprecite your help in resolving this tricky issue... I am trying implementing Recurrsive TreeView in MS. Access 2003 ADP project. So far, no luck :( The Problem: This sample snippet is all written for DAO and doesn't work in ADO
2
2683
by: Janus | last post by:
Hello. I need a little advice for populating the treeview control. I dont want my application to hang while populating the treeview, there is a lot of data what's the best approach? Maybe something eventbased but how? please help... Should I avoid populating the treeview control using a thread?
0
1173
by: N-Mayne | last post by:
Hi i was wondering if anyone knew how to Populating a TreeView control with the contents of a class and varibles etc, like netbean does but in C#. Thanks Nick Posted Via Usenet.com Premium Usenet Newsgroup Services ---------------------------------------------------------- ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
1
2194
by: naijacoder naijacoder | last post by:
Hi Guys, I have an application below that is treeview menu populated from the database which works with asp.net webmatrix.But when i put it into code behind in Visual Studio.Net it gives the errors "TreeNode Not defined" "name TreeeView1 not defined" Can anybody tell me what 'm doing wrong? Sub Page_load(Sender As Object, E As EventArgs)
0
1299
by: Erland | last post by:
Hello all, I have just installed visual studio .net 2005 and started developing programs in asp.net 2.0. I have a scenerio where I have to populate treeview child nodes based on the entries being entered in textbox,but there is this thing I need to consider. Values in treeview nodes should be populated as nodes, all child nodes in this case, as soon as vales are being entered in textbox. That is to say, if I enter H in textbox then H...
0
2297
by: drop | last post by:
Hi, I'm currently working with the Treeview control in ASP .Net 2.0. The tree is filled dynamically based on data contained in a MySQL Database. Here is the exact behavior I want : 1 - User clicks on a node to expand it. 2 - Add a child node to the node clicked by the user saying the tree is loading that part. So here, I also need to expand the node clicked by
2
3191
by: Steve Arndt | last post by:
I'm trying to populate a vb.net treeview using a SQLDataReader at Treeview1_BeforeExpand. Basically I have a Treeview with 5 parent nodes and 1 dummy child node per parent. The first parent node is called Address is the parent I'm trying to add new children under. When BeforeExpand is triggered, it removes the dummy child under the Adress parent node based on e.Node.FirstNode.Remove. Then runs a private sub called PopulateNode with...
0
1474
by: hardieca | last post by:
Hi, I have created a treeview bound to a sitemap provider. I have put it into a user control (the control will be used for similar, but not always identical, functionality). The treeview expresses the hierarchy of sections in my website. In a page that edits sections, I would like to use the treeview to allow the user to select a parent section. My treeview is accurately showing my section tree, but of course when I click a link I am...
2
3464
by: Maddy | last post by:
I need to populate a treeview from a text file. The data in it is in the following form 1. (Parent Node) (a) (Child Node) (b) (Child Node) .. .. .. (k) (Child Node)
0
9636
marktang
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...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
Oralloy
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...
0
10138
jinu1996
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...
1
10074
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,...
0
9930
tracyyun
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...
1
4037
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
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
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...

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.