2013-02-27 82 views
0

以下aspx代码中的ListView嵌套在另一个ListView中。下面的代码用于包装嵌套的ListView。我希望在每次迭代时使用包装器ListView在嵌套ListView的数据源中传递属性“Comments”。我试图用事件“ItemDataBound”(这个事件用于包装器ListView)的代码隐藏功能来做到这一点,但是当我运行代码时,我正在冒这个异常:DataBinding:'System.Collections.Generic.HashSet`1 [[BlogProfile.Data.Comment,BlogProfile.Data,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null]]'不包含名称为'Author'的属性。所有我想要的是每次包装ListView传递不同的数据源到嵌套的ListView和这个嵌套ListView采取与“Eval(...)”这个数据源就像我写在aspx代码。我在这里想念什么。我认为这个问题可能是因为我没有在这里使用正确的事件?使用Datasource进行嵌套控制

ASPX代码:

 <asp:ListView ID="CommentListView" runat="server" > 
      <ItemTemplate> 
       <div class="postComments"> 
        <span class="authorComment"><%# Eval("Author") %></span> 
         : 
         <span class="commentContent"><%# Eval("Message") %></span> 
       </div> 
       </ItemTemplate> 
     </asp:ListView> 

后面的代码:

protected void PostsListView_ItemDataBound(object sender, ListViewItemEventArgs e) 
    { 
     BlogProfileEntities blogProfile = new BlogProfileEntities(); 
     var listview = e.Item.FindControl("CommentListView") as ListView; 
     var hiddenfield = e.Item.FindControl("CurrentPostIDHiddenField") as HiddenField; 
     int id = int.Parse(hiddenfield.Value); 
     listview.DataSource = (from p in blogProfile.Posts 
           where p.PostID == id 
           select p.Comments).ToList(); 
     listview.DataBind(); 
    } 

回答

0

这个问题是基于你的实体框架。它发生在将ADO.NET实体FW组件添加到您的系统中时。请再次读取组件。还请检查您的实体中添加的表格列名FW