我有以下代碼。它的工作原理是這樣,但是...我並不總是會在RSS源中有偶數個項目所以,在表的最後,我最後一行可能只有一個表格單元格。那麼,有沒有辦法計算ItemTemplates和AlternatingItemTemplate的數量,所以如果它是一個奇數,我可以添加另一個單元格<td> </td></tr>
並關閉表格行?從ASP.net中的XmlDataSource在ListView中計數ItemTemplate
<asp:XmlDataSource ID="SomeFeed" DataFile="TestSomeRSS.xml" XPath="rss/channel/item" runat="server"></asp:XmlDataSource>
<asp:ListView ID="SomeFeedScroller" DataSourceID="SomeFeed" ItemPlaceholderID="SomePlcID" runat="server">
<LayoutTemplate>
<table id="ListingsTable" cellpadding="0" cellspacing="0" align="center">
<asp:PlaceHolder ID="SomePlcID" runat="server"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr style="vertical-align:top;">
<td class="bnotes" style="width:325px;padding:5px;">
<%# XPath("title")%><br />
<%# XPath("description")%><br />
</td>
</ItemTemplate>
<AlternatingItemTemplate>
<td class="bnotes" style="width:325px;padding:5px;">
<%# XPath("title")%><br />
<%# XPath("description")%><br />
</td>
</tr>
</AlternatingItemTemplate>
</asp:ListView>
在此先感謝您的幫助。
也許我完全接近這個完全錯誤的。我正在嘗試的是使用RSS提要中的數據構建表格。該表是兩列寬。每個單元格將包含每個項目所需的所有數據。 – Soren
如果我嘗試: <%#的XPath ( 「標題」)%>
<%#的XPath( 「標題」)%>
ItemTemplate中> 然後我會在兩個單元格中獲得相同的內容。 –
Soren
<%#的XPath( 「描述」)%>
<%#的XPath( 「描述」)%>
@Soren - 你將兩個單元放在同一個Item Template中。你是否試圖並排顯示兩個單元格?另外,你可以用XML的樣例更新你的問題嗎? – Tim