473,385 Members | 1,341 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.

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 1337
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.1E0F8640
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;&nbsp;&n bsp;&nbsp;
ref_id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
level<BR>--------------------------------------<BR>A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
0<BR>A1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1<BR>A2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1<BR>A3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1<BR>A11&nbsp;&nbsp;&nbsp;&nbsp;
A1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
2<BR>A12&nbsp;&nbsp;&nbsp;&nbsp;
A1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
2<BR>A21&nbsp;&nbsp;&nbsp;&nbsp;
A2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
2<BR>A31&nbsp;&nbsp;&nbsp;&nbsp;
A3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
2<BR>A211&nbsp;&nbsp;
A21&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp; 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;&nbsp;&nbsp; [+]
A1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;
A11<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;
A12<BR>&nbsp;&nbsp;&nbsp; [+]
A2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp; [+]
A21<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
A211<BR>&nbsp;&nbsp;&nbsp; [+]
A3<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp; A31<BR><BR>Can somebody
please show me how to do this?<BR><BR>Many thanks in
advance,<BR>Mike<BR><BR><BR></DIV></BODY></HTML>

------=_NextPart_000_0071_01C684EC.1E0F8640--


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.com> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.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.1E0F8640
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;&nbsp;&n bsp;&nbsp;
ref_id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
level<BR>--------------------------------------<BR>A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
0<BR>A1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1<BR>A2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1<BR>A3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1<BR>A11&nbsp;&nbsp;&nbsp;&nbsp;
A1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
2<BR>A12&nbsp;&nbsp;&nbsp;&nbsp;
A1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
2<BR>A21&nbsp;&nbsp;&nbsp;&nbsp;
A2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
2<BR>A31&nbsp;&nbsp;&nbsp;&nbsp;
A3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
2<BR>A211&nbsp;&nbsp;
A21&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;
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;&nbsp;&nbsp; [+]
A1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;
A11<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;
A12<BR>&nbsp;&nbsp;&nbsp; [+]
A2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp; [+]
A21<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
A211<BR>&nbsp;&nbsp;&nbsp; [+]
A3<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp; A31<BR><BR>Can
somebody
please show me how to do this?<BR><BR>Many thanks in
advance,<BR>Mike<BR><BR><BR></DIV></BODY></HTML>

------=_NextPart_000_0071_01C684EC.1E0F8640--

Jun 2 '06 #3

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

Similar topics

2
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...
0
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...
2
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...
0
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...
1
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...
0
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...
0
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...
2
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...
0
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...
2
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)
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
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.