0

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.

    <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> 
Cœur
  • 37,241
  • 25
  • 195
  • 267
roncansan
  • 2,310
  • 6
  • 27
  • 34

2 Answers2

0

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
  • 208,112
  • 36
  • 198
  • 279
  • <% int i=0;%>
    <% if(i!=3){ %>
    //display content
    <% ++i;} else {%> //display Google ads <% ++i;}%>
    – roncansan Jul 13 '10 at 14:35
  • Nope, HeaderTemplate is only executed once. – Djuro May 28 '18 at 11:36
  • @Djuro: HeaderTemplate *should* only be executed once. There's only one header row. – David May 28 '18 at 11:38
  • @David why "should"? Header template is executed only once, and you cant make it execute more times. – Djuro May 28 '18 at 12:41
  • @Djuro: Because a header occurs once, at the top of the grid. That's what a header *is*. What exactly are you trying to do and what does it have to do with this *ancient* and barely useful Stack Overflow question? If you have a question to ask, ask it in its own question. – David May 28 '18 at 12:44
  • @David oh, sorry, dont know why this question popped up to me, i thought it is a new one, i didnt notice that is really ancient question :) – Djuro May 28 '18 at 12:49
0
<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
  • 2,310
  • 6
  • 27
  • 34