显示对象列表中的值(在对象列表中)

时间:2015-01-16 18:51:50

标签: c# asp.net

我有一个发布对象列表

 List<Post> p = new List<Post>();

POST的构造函数

 public Post(int postID, string title, DateTime date, string body, List<Comment> comments)
    {
        this.postID = postID;
        this.title = title;
        this.date = date;
        this.body = body;
        this.comments = comments;
    }

正如你在构造函数中看到的那样,帖子的列表包含一个评论列表。

评论的构造函数

public Comment(int commentId, DateTime date, string body) 
    {
        this.commentID = commentID;
        this.date = date;
        this.body = body;
    }

我的问题是在我的page.aspx

中显示这些评论

Page.aspx

<asp:Repeater runat="server" ID="repeater1" ItemType="OOPBLOG.Model.Classes.Post" 
    SelectMethod="LoadPosts"
    OnCallingDataMethods="postView">

    <ItemTemplate>
        <table>
        <tr>
            <td><%#Item.Title %></td>
        </tr>
        <tr>
            <td><%#Item.Body %></td>
        </tr>
        <tr>
            <td><%#Item.Date %></td>
        </tr>
        <tr>
            <td><%#Item.comment[0].Body%>></td>
        </tr>          
        </table>
    </ItemTemplate>

如你所看到的那样,如果只显示列表的第一条评论,我将如何使用foreach或for循环显示所有评论?

顺便说一句,我使用的是模型绑定和webforms。

0 个答案:

没有答案
相关问题