显示博客中评论的嵌套回复

时间:2018-08-06 05:10:22

标签: c# asp.net repeater

我正在开发一个博客,其中包含一个部分,可以从用户那里获得一些评论和答复。第一部分是我的代码,用于获取评论和答复如下:

C#代码:

var a = commentBLL.GetAll(BlogID);
rp_MainComments.DataSource = a;
rp_MainComments.DataBind();

protected void rp_MainComments_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || 
        e.Item.ItemType == ListItemType.AlternatingItem)
    {
        LinkButton btn = e.Item.FindControl("btn_Comment_Reply") as LinkButton;
        ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(btn);

        HiddenField lt = (HiddenField)e.Item.FindControl("hf_Main_CommentID");

        Repeater rpcommentreply = (Repeater)e.Item.FindControl("rp_Comment_Reply");

        Panel panel_Comment_Reply = e.Item.FindControl("panel_Comment_Reply") as Panel;

        if (!string.IsNullOrEmpty(lt.Value))
        {
            var b = commentBLL.GetByCommentID(Convert.ToInt32(lt.Value));
            rpcommentreply.DataSource = b;
            rpcommentreply.DataBind();

            panel_Comment_Reply.Visible = false;
        }
    }
}

ASPX代码:

<asp:Repeater ID="rp_MainComments" OnItemDataBound="rp_MainComments_ItemDataBound" OnItemCommand="rp_MainComments_ItemCommand" runat="server">
    <ItemTemplate>
        <asp:HiddenField ID="hf_Main_CommentID" runat="server" Value='<%# Eval("Comment_Id") %>' />
        <ul class="comments">
            <li>
                <div class="comment">
                    <div class="img-thumbnail d-none d-sm-block">
                        <%--<asp:Image ID="Image_7" CssClass="avatar" runat="server" ImageUrl="http://placehold.it/40x40" />--%>
                        <i class="fa fa-user fa-fw fa-5x"></i>
                    </div>
                    <div class="comment-block">
                        <div class="comment-arrow"></div>
                        <span class="comment-by">
                            <strong><%# Eval("Name") %></strong>
                            <span class="float-right">
                                <span>
                                    <asp:LinkButton ID="btn_Comment_Reply" Text="Reply" ClientIDMode="AutoID" runat="server" OnClick="btn_Comment_Reply_Click" CommandName="Edit" CommandArgument='<%# Eval("Comment_Id") %>' /></span>

                            </span>
                        </span>
                        <p><%# Eval("Message") %></p>
                        <span class="date float-right">
                            <%# Eval("Comment_Date") %></span>
                    </div>
                </div>
            </li>
            <li>
                <asp:HiddenField ID="hf_PanelValue" Value='<%# Container.ItemIndex %>' runat="server" />
                <asp:Repeater ID="rp_Comment_Reply" OnItemCommand="rp_Comment_Reply_ItemCommand" runat="server">
                    <ItemTemplate>
                        <ul class="comments reply" id="commentreply">
                            <li>
                                <div class="comment">
                                    <div class="img-thumbnail d-none d-sm-block">
                                        <%--<asp:Image ID="Image_8" CssClass="avatar" runat="server" ImageUrl="http://placehold.it/40x40" />--%>
                                        <i class="fa fa-user fa-5x fa-fw"></i>
                                    </div>
                                    <div class="comment-block">
                                        <div class="comment-arrow"></div>
                                        <span class="comment-by">
                                            <strong><%# Eval("Name") %></strong>
                                            <span class="float-right">
                                                <span>
                                                    <asp:LinkButton ID="btn_Reply" Text="Reply" ClientIDMode="AutoID" runat="server" OnClick="btn_Reply_Click" CommandName="Edit" CommandArgument='<%# Eval("Parent_Id") %>' /></span></span>
                                        </span>
                                        <p><%# Eval("Message") %></p>
                                        <span class="date float-right"><%# Eval("Comment_Date") %></span>
                                    </div>
                                </div>
                            </li>
                        </ul>
                    </ItemTemplate>
                </asp:Repeater>
            </li>
        </ul>
    </ItemTemplate>
</asp:Repeater>

这是输出:

display comments and replies

现在,我想显示帖子中用户答复的嵌套答复,它仅显示到第二级,但是我需要第三级和第四级。

怎么可能?

0 个答案:

没有答案