B
bennett
How can I do a loop from 1 to 5, where on line 1 I print 1 space
followed by a button, on line 2 I print 2 spaces followed by a button,
on line 3 I print 3 spaces followed by a button, etc.?
I tried this code:
for (int i = 1; i <= 5 ; ++i)
{
for (int j = 1; j <= i; ++j)
{
Response.Write(" ");
}
Response.Write("<asp:Button id=\"Button" +
i.ToString() +
"\" runat=\"server\" Text=\"Button\"></asp:Button>" +
"<br>\n");
}
but that didn't work, since Response.Write just sent the characters
"<asp:Button" etc. to the browser; ASP.Net did not interpret them.
Or maybe someone could think of a better way to do what I'm trying to
do:
I have a database table of message posts; some messages are "replies"
to other messages, and each record in the table has a parent_post_id
that refers to the ID of the parent post, if there is one. What I'm
actually trying to do is display the messages in a hierarchical way,
i.e. the first top-level post, followed by all of its direct replies
that are indented by X spaces, and each reply is also followed by all
of *its* replies indented by 2X spaces, etc., the familiar way in which
a hierarchy of message posts is usually displayed. Each message post
is displayed as a custom control.
The ideal solution would be to do it recursively, having a custom
control for a "post" that displays the current post and then has a list
of "post" controls for all the replies, indented X spaces further over
than the parent. This would result in all the replies to the replies
being displayed as well, all the way down to the last replies.
Unfortunately ASP.Net does not allow user controls to contain
themselves recursively.
So my plan is to do it iteratively: get the first top-level post, then
get a list of all its replies, then go through and print the replies,
but after checking each reply, check if *it* has any replies, and go
and print those... etc. But to do that I need a way to "print" the
user control that represents a message post. Hence my original
question.
followed by a button, on line 2 I print 2 spaces followed by a button,
on line 3 I print 3 spaces followed by a button, etc.?
I tried this code:
for (int i = 1; i <= 5 ; ++i)
{
for (int j = 1; j <= i; ++j)
{
Response.Write(" ");
}
Response.Write("<asp:Button id=\"Button" +
i.ToString() +
"\" runat=\"server\" Text=\"Button\"></asp:Button>" +
"<br>\n");
}
but that didn't work, since Response.Write just sent the characters
"<asp:Button" etc. to the browser; ASP.Net did not interpret them.
Or maybe someone could think of a better way to do what I'm trying to
do:
I have a database table of message posts; some messages are "replies"
to other messages, and each record in the table has a parent_post_id
that refers to the ID of the parent post, if there is one. What I'm
actually trying to do is display the messages in a hierarchical way,
i.e. the first top-level post, followed by all of its direct replies
that are indented by X spaces, and each reply is also followed by all
of *its* replies indented by 2X spaces, etc., the familiar way in which
a hierarchy of message posts is usually displayed. Each message post
is displayed as a custom control.
The ideal solution would be to do it recursively, having a custom
control for a "post" that displays the current post and then has a list
of "post" controls for all the replies, indented X spaces further over
than the parent. This would result in all the replies to the replies
being displayed as well, all the way down to the last replies.
Unfortunately ASP.Net does not allow user controls to contain
themselves recursively.
So my plan is to do it iteratively: get the first top-level post, then
get a list of all its replies, then go through and print the replies,
but after checking each reply, check if *it* has any replies, and go
and print those... etc. But to do that I need a way to "print" the
user control that represents a message post. Hence my original
question.