populating treeview

M

Mike

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
 
G

gmiley

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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&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;&nbsp;&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;&nbsp; [+]
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;&nbsp; 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--
 
M

Mike

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 said:
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>
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sp;&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;&nbsp;&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;&nbsp; [+]
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;&nbsp; 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--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top