Google Answers Logo
View Question
 
Q: in ASP.Net, displaying a hierarchy of message board posts ( No Answer,   2 Comments )
Question  
Subject: in ASP.Net, displaying a hierarchy of message board posts
Category: Computers > Programming
Asked by: bennetthaselton-ga
List Price: $25.00
Posted: 15 May 2005 16:06 PDT
Expires: 14 Jun 2005 16:06 PDT
Question ID: 521987
(This is a programming question but I'm not asking for code to be
written for me, just a general answer to *how* to do something.)

I am working on an ASP.Net project and I am trying to create a
hierarchical display of user posts on a message board.  So, for
example, you have a top-level post, and then you have a list of all
the replies to that post indented by X spaces, and then below each
reply you have in turn all the replies to *that* reply indented by 2X
spaces, etc.  However, I also want each post, when it's displayed, to
be displayed as a user-defined custom control, so that I have one
centralized place where I can define how a "message board post" is
displayed (the name of the user, the time of the post, links that you
can click to reply or bookmark the post, etc.).

IF ASP.Net allowed user controls to recursively contain themselves,
then the easiest way would be: Make a custom control called
'RecursiveUserPost' that displays the post's author, subject, and
timestamp, and then contains a DataRepeater that is indented over by a
few spaces, and query for all posts that have the current post as
their 'parent' and use that to populate the DataRepeater, and have the
ItemTemplate for the DataRepeater recursively contain an instance of
RecursiveUserPost that is bound to that data.

Unfortunately, ASP.Net does not allow controls to recursively contain
themselves so that won't work.

I cannot use a pre-fab ASP.Net message board solution from another
site because I'm not simply trying to add a message board system to my
site, I'm trying to write a new *kind* of message board.

Is there any way to do what I want -- have a user-definable control
that displays a message board post, followed by all of its replies
indented by a few spaces, with each reply followed by its own replies,
etc.?
Answer  
There is no answer at this time.

Comments  
Subject: Re: in ASP.Net, displaying a hierarchy of message board posts
From: willcodeforfood-ga on 16 May 2005 12:52 PDT
 
I've used two methods to render recursive HTML layouts:

1) Write your own class that renders all of the HTML. Use a
StringBuilder to generate large blocks of HTML and then place them
into a PlaceHolder or Literal control.

2) Generate a series of controls and append them to a PlaceHolder
control.  You'll end up with alternating Literal controls with your
custom MsgBoardPost control.  The Literal controls will contain only
the HTML used to indent your HTML structure.  To maximize design-time
usability, put the DataGrid and other built-in ASP.NET controls in a
web user control and use set/get to initialize and retrieve state from
them.

If all you need to do is indent sections appropriately, couldn't you
just place the posts in a series of tables like this:

<table>                   <-- table tag generated by DataGrid
  <tr>
    <td>                  <-- td tag generated by Cell 1 for 1st DataGridItem
      <table>             <-- you parse the HTML content for this cell in code
        <tr>
          <td style="width:0px">
          <td>Level 1 Post ...</td>
        </tr>
      </table>
    </td>
    <td>                  <-- td tag generated by Cell 1 for 2nd DataGridItem
      <table>             <-- you parse the HTML content for this cell in code
        <tr>
          <td style="width:20px">
          <td>Level 2 Post ...</td>
        </tr>
      </table>
    </td>
    <td>                  <-- td tag generated by Cell 1 for 3rd DataGridItem
      <table>             <-- you parse the HTML content for this cell in code
        <tr>
          <td style="width:40px">
          <td>Level 3 Post ...</td>
        </tr>
      </table>
    </td>
    <td>                  <-- td tag generated by Cell 1 for 4th DataGridItem
      <table>             <-- you parse the HTML content for this cell in code
        <tr>
          <td style="width:20px">
          <td>Level 2 Post ...</td>
        </tr>
      </table>
    </td>
  </tr>
</table>

This would allow you to use a DataGrid with a single column, although
you'd need to modify the HTML in each Cell, rather than relying on the
default HTML generated by the DataGrid.
Subject: Re: in ASP.Net, displaying a hierarchy of message board posts
From: bennetthaselton-ga on 21 May 2005 20:15 PDT
 
I ended up trying your second method and it worked!  The real push in
the right direction was the tip about PlaceHolder controls -- once I
looked those up, I could start to figure out how to use them to create
a recursive control.

You gave me exactly what I was asking for, since I was just looking
for a broad description and not a coded solution -- I'll pay if you
submit it again as an answer :)

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy