[英]Nested repeater - Access item count in parent repeater
我是ASP.NET的新手,正在將某些頁面從ColdFusion轉換為.NET和C#。 在ColdFusion中,我在記錄集,日程表和日程表詳細信息之間進行嵌套循環,為每個日程表及其詳細信息創建一個表,並隱藏除活動表以外的所有表。 渲染表格時,我將在表格的第一行中創建導航機制,該機制將顯示上一個或下一個表格並隱藏當前表格(通過jQuery):
<< 07/15/2019 - 07/22/2019 >>
[schedule details rows]
在Coldfusion中這是微不足道的,但是我花了數小時試圖在ASP.NET中復制它,但沒有成功。 我需要知道項目總數(父記錄的數量),並有條件地呈現人字形,具體取決於我是在第一條記錄,最后一條記錄還是在記錄之間。
我嘗試使用會話變量,在后面的代碼中:
int count = repScheduleDates.Items.Count;
Session["scheduleDatesCount"] = count;
Debug.WriteLine("Session[scheduleDatesCount]: " + Session["scheduleDatesCount"]);
如果我有2條記錄,調試打印將顯示2。但是,在aspx文件中
<%#Session["scheduleDatesCount"]%>
什么都不顯示(不是0;只是沒有輸出)。
如果我在aspx中執行此操作:
<%# repScheduleDates.Items.Count %>
顯示當前商品編號; 0或1,不是總數。
<asp:Repeater runat="server" id="repScheduleDates">
<HeaderTemplate>
<table style="border:1px solid #0000FF;">
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:#FF6600; color:#000000; font-size: large;">
<td style="text-align: center;" colspan="6">
<%-- I need a conditional statement here to add the appropriate class if first record or not --%>
<i id="leftNav_<%#Container.ItemIndex%>" class="fa fa-chevron-left"></i>
<%#Eval("schStartDate") %> - <%#Eval("schEndDate") %>
<%-- I need a conditional statement here to add the appropriate class if last record or not --%>
<i id="rightNav_<%#Container.ItemIndex%>" class="fa fa-chevron-right"></i>
</td>
</tr>
[more parent stuff...]
<asp:Repeater id="repScheduleDetails" runat="server" OnDataBinding="repScheduleDetails_DataBinding">
<ItemTemplate>
[output child stuff...]
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
如何獲得父轉發器中的項目總數?
<%#Session["scheduleDatesCount"]%>
這不會顯示記錄。
無論使用
<%=Session["scheduleDatesCount"]%>
或在.cs頁上創建公共變量計數,並在aspx頁上顯示,例如
<%=count%>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.