how to do a hierarchical listing of posting threads?

B

Bennett Haselton

I want to display a hierarchical listing of items from a database
table, where, say, each row in the table has an "ID" field and a
"parent_id" field giving the ID of its parent (NULL if it's at the top
level of the hierarchy) -- like message posts and their replies. Is
there a built-in way to do this, or a generally accepted simplest way?

My first idea was to create a user control like HierarchicalListing
that contains a Repeater, and the repeater's ItemTemplate would itself
contain an instance of HierarchicalListing. Then when putting the
HierarchicalListing on the page, you set its DataSource and have it
query for all rows where the parent_id is null, and databind the
Repeater to the results -- and then inside the Repeater, look at the
ID of the current row, and for the HierarchicalListing inside the
Repeater, have it query for all rows where the parent_id was equal to
that ID. That would give you a hierarchical listing of all the rows,
if ASP.Net allowed it.

Unfortunately if you try adding
<%@ Register TagPrefix="uc1" TagName="HierarchicalPostListing"
Src="HierarchicalPostListing.ascx" %>
to the top of HierarchicalPostListing.ascx itself, you get a run-time
error that circular file references are not allowed.

So, is there a way for a user control to be nested inside itself (or
rather, to be nested conditionally inside itself, so you don't get an
infinite recursion)? More importantly, is there a generally accepted
way to do a hierarchical listing like what I'm trying to do?

-Bennett
 
B

Bennett Haselton

I thought I remembered something about a "TreeView" control and I tried
looking it up before coming up with my approach, but when I searched in
the MSDN index with the ".NET Framework" filter set, it only showed the
Windows Forms TreeView control. Then when I removed that filter, I did
find the Microsoft.Web.UI.WebControls.TreeView control.

However,
http://msdn.microsoft.com/library/default.asp?url=/workshop/webcontrols/
overview/overview.asp says that the controls in that namespace "deliver
content that renders in all commonly used browsers, while taking
advantage of powerful features supported by Internet Explorer 5.5 or
later versions". Now I'm really confused:

If they work in all browsers, then why do they get their own namespace,
where they're officially unsupported and Visual Studio .Net has no
built-in support for them?

And if they don't work in all browsers, then I can't use those anyway.

Anyway,
http://msdn.microsoft.com/library/default.asp?url=/workshop/webcontrols/
overview/overview.asp makes it look like the TreeView is for
hierarchical views that needs to be expandable and collapsable, which is
why it requires fancy tricks like client-side scripting and DHTML.
That's overkill for what I want to do; I just need a hierarchical view
that doesn't need to change.

-Bennett
 

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

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top