Asp.net 转发器行数
Asp.net Repeater row count
谁能告诉我如何在中继器中进行 运行 计数?我已经使这段代码有效,但变量 (RC) 似乎没有计数。这是代码:
<asp:Repeater ID="FPRepeater" runat="server" DataSourceID="FPDataSource">
<ItemTemplate>
<%Dim RC As Int32
Dim divc As String%>
<%If (RC + 1 Mod 1 = 0) Then
divc = "one-third mobile-collapse"
ElseIf (RC + 1 Mod 2 = 0) Then
divc = "one-third one-third-second mobile-collapse"
ElseIf (RC + 1 Mod 3 = 0) Then
divc = "one-third one-third-last mobile-collapse"
End If%>
<div class="<%=divc %>">
<img src="/images/<%# Eval("ImName")%>" alt="<%# Eval("Heading")%>" />
<h2><%# Eval("Heading")%></h2>
<p><%# System.Web.HttpUtility.HtmlDecode(Eval("ContText"))%></p>
</div>
<%RC = (RC + 1)%>
</ItemTemplate>
</asp:Repeater><!--/info-box-->
<asp:SqlDataSource ID="FPDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:Conn %>" SelectCommand="SELECT * FROM [tblContent] WHERE (Location = 'Home') AND (Deleted = 'False') Order By OrderBy ASC">
我以为 <%RC = (RC + 1)%> 会在每次重复该行时自动将 1 添加到 RC。
它目前所做的只是拉回 1、1、1 而不是 1、2、3。我哪里错了?谢谢
只需在转发器控件上方的行下方写下
<script runat="server">
Dim RC As Int32 = 1
</script>
以及从 ItemTemplate
中删除 Dim RC As Int32
谁能告诉我如何在中继器中进行 运行 计数?我已经使这段代码有效,但变量 (RC) 似乎没有计数。这是代码:
<asp:Repeater ID="FPRepeater" runat="server" DataSourceID="FPDataSource">
<ItemTemplate>
<%Dim RC As Int32
Dim divc As String%>
<%If (RC + 1 Mod 1 = 0) Then
divc = "one-third mobile-collapse"
ElseIf (RC + 1 Mod 2 = 0) Then
divc = "one-third one-third-second mobile-collapse"
ElseIf (RC + 1 Mod 3 = 0) Then
divc = "one-third one-third-last mobile-collapse"
End If%>
<div class="<%=divc %>">
<img src="/images/<%# Eval("ImName")%>" alt="<%# Eval("Heading")%>" />
<h2><%# Eval("Heading")%></h2>
<p><%# System.Web.HttpUtility.HtmlDecode(Eval("ContText"))%></p>
</div>
<%RC = (RC + 1)%>
</ItemTemplate>
</asp:Repeater><!--/info-box-->
<asp:SqlDataSource ID="FPDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:Conn %>" SelectCommand="SELECT * FROM [tblContent] WHERE (Location = 'Home') AND (Deleted = 'False') Order By OrderBy ASC">
我以为 <%RC = (RC + 1)%> 会在每次重复该行时自动将 1 添加到 RC。
它目前所做的只是拉回 1、1、1 而不是 1、2、3。我哪里错了?谢谢
只需在转发器控件上方的行下方写下
<script runat="server">
Dim RC As Int32 = 1
</script>
以及从 ItemTemplate
中删除Dim RC As Int32