Asp.net中继器行数

时间:2015-03-19 14:04:05

标签: asp.net vb.net repeater

有谁能告诉我如何在转发器中进行运行计数?我已经使这个代码有效但变量(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">

我认为会发生的是&lt;%RC =(RC + 1)%&gt;每次重复行时都会自动为RC添加1。

它目前所做的只是拉回1,1,1而不是1,2,3。我哪里错了?感谢

1 个答案:

答案 0 :(得分:0)

只需放下转发器控件上方的行以下

<script runat="server">
        Dim RC As Int32 = 1
</script>

以及从ItemTemplate

中删除Dim RC As Int32