views:

19

answers:

2

I want to insert Google ads on a asp.net repeater on the 3rd iteration. I'm trying to figure out how to do this, here is what I have. Thanks for your help

    <asp:Repeater ID="Repeater1" runat="server" >
            <HeaderTemplate>
            </HeaderTemplate>
            <ItemTemplate>
                <div class="Pl">
                 <%# int i=0; if(i!=3){ %>
                        <div class="PlFoto">
                            //display content  
                        </div>
                 <%# ++i;} else {%>
                          //display Google ads
                 <%# ++i;}%>
                </div>
        </ItemTemplate>
    </asp:Repeater> 
A: 

Will "i" ever be equal to 3? Won't the "int i=0;" be executed with each iteration? Try putting that declaration outside the repeater and see if it works better.

David
<asp:Repeater ID="Repeater1" runat="server" > <HeaderTemplate><% int i=0;%> </HeaderTemplate> <ItemTemplate> <div class="Pl"> <% if(i!=3){ %> <div class="PlFoto"> //display content </div> <% ++i;} else {%> //display Google ads <% ++i;}%> </div> </ItemTemplate> </asp:Repeater>
roncansan
Is that working better?
David
A: 
<asp:Repeater ID="Repeater1" runat="server" >
    <HeaderTemplate>
    <% int i = 0;%>
    </HeaderTemplate>
    <ItemTemplate>
        <div class="Pl">
        <%  if (i != 3) { %>
            <div class="PlFoto"></div>
        <% ++i;}else{ %>
            <div class="ads"></div>
        <% ++i;   } %>
        </div>
    </ItemTemplate>
</asp:Repeater>
roncansan