0
我想使工作嵌套ListView幾天,但我不明白爲什麼它只顯示第一個選定的數據。下面是一些代碼: ASPX:嵌套ListView只顯示第一個選定的數據
<asp:ListView ID="ListForumCategories" runat="server">
<ItemTemplate>
<div class="accordionButton">
<table><%--class="Categories"--%>
<tr>
<td class="CatName">
<%# Eval("CatName") %>
</td>
<td class="SubjectNumber">
0
</td>
<td class="AllComment">
0
</td>
<td class="CreationDate">
<%# Eval("WhenCreated") %>
</td>
<td class="LastModification">
<%# Eval("WhenCreated") %>
</td>
</tr>
</table>
</div>
<asp:ListView ID="ListSubjectsToCategories" DataSource='<%# Eval("RelatedSubjects") %>' runat="server">
<ItemTemplate>
<div class="accordionContent"><%# Eval("SubjID") %> <%# Eval("SubjectName") %> <%# Eval("WhenCreated") %></div>
</ItemTemplate>
</asp:ListView>
</ItemTemplate>
</asp:ListView>
查詢
public static List<ForumCategoriesModel> ListForumCategories()
{
try
{
return BW_Model.ForumCategories.Select(x => new ForumCategoriesModel
{
CatID = x.CatID,
CatName = x.CatName,
WhenCreated = x.WhenCreated
}).ToList();
}
catch
{
throw new Exceptions.SomethingWrongException();
}
}
public static List<ForumSubjectsModel> ListForumSubjectByCategoryID(int catid)
{
try
{
return BW_Model.ForumSubjects.Select(x => new ForumSubjectsModel
{
SubjID = x.SubjID,
WhoCreated = x.WhoCreated,
WhichCategory = x.WhichCategory,
SubjectName = x.SubjectName,
SubjectText = x.SubjectText,
WhenCreated = x.WhenCreated
}).Where(x => x.WhichCategory == catid).ToList();
}
catch
{
throw new Exceptions.SomethingWrongException();
}
}
類
public class ForumCategoriesModel
{
public Int32 CatID { get; set; }
public String CatName { get; set; }
public DateTime WhenCreated { get; set; }
public List<ForumSubjectsModel> RelatedSubjects { get { return bw_forum_sqlchannel.ListForumSubjectByCategoryID(CatID); } }
}
public class ForumSubjectsModel
{
public Int32 SubjID { get; set; }
public Int32 WhoCreated { get; set; }
public Int32 WhichCategory { get; set; }
public String SubjectName { get; set; }
public String SubjectText { get; set; }
public DateTime WhenCreated { get; set; }
}
我應該得到一個列表<>回來,有很多元素,但它只顯示每個類別的第一個。
現在試圖解決這個問題2天...如果你能幫我解決問題,那將會非常有用。提前致謝。
啊,忘了後面的代碼:):
categories = bw_forum_sqlchannel.ListForumCategories();
ListForumCategories.DataSource = categories;
ListForumCategories.DataBind();
解決方案:
<asp:ListView ID="ListSubjectsToCategories" DataSource='<%# Eval("RelatedSubjects") %>' runat="server">
<ItemTemplate>
<div class="accordionContent"><%# Eval("SubjID") %> <%# Eval("SubjectName") %> <%# Eval("WhenCreated") %></div>
</ItemTemplate>
</asp:ListView>
變成了:
<div class="accordionContent">
<asp:ListView ID="ListSubjectsToCategories" DataSource='<%# Eval("RelatedSubjects") %>' runat="server">
<ItemTemplate>
<%# Eval("SubjID") %> <%# Eval("SubjectName") %> <%# Eval("WhenCreated") %>
</ItemTemplate>
</asp:ListView>
</div>
'RelatedSubjects'屬性是否包含預期的數據,問題是它的所有內容都沒有顯示在內部'ListView'中?還是這樣,'RelatedSubjects'甚至不會獲取它應該的所有行? – user1429080
@ user1429080我不知道,我無法測試它。 列表視圖的輸出是這樣的: [代碼]第一類別 第一個項目屬於第一類別 第二類別 第一個項目屬於第二類[/代碼] 但應該有屬於這些類別的更多的項目,但它只顯示第一個。我認爲可能相關的主題有所有的數據,但我不知道它 – davegen
@ user1429080哇,我發現它在頁面源...怎麼會這樣CSS? :D讓我試着修復它。 – davegen