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.
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
ref_id
level<BR>--------------------------------------<BR>A
-
0<BR>A1
A
1<BR>A2
A
1<BR>A3
A
1<BR>A11
A1
2<BR>A12
A1
2<BR>A21
A2
2<BR>A31
A3
2<BR>A211
A21
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> [+]
A1<BR>
A11<BR>
A12<BR> [+]
A2<BR> [+]
A21<BR>
A211<BR> [+]
A3<BR> 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--