title: access items in repeater
body: <p>I have a repeater and I am trying to access labels inside it. Here is my method:</p>
  
  <pre><code>protected void ButtonlarıTemizle()
      {
          int n = 0;
          foreach (RepeaterItem item in Repeater1.Items)
          {
              n++;
              Label lbl = item.FindControl("lblApproved") as Label;
              Button btn = item.FindControl("btnAssignApproved") as Button;
              if (lbl.Text.Equals("Satışa Dönmüştür"))
              {
                  btn.Visible = false;
                  lbl.ForeColor = System.Drawing.Color.Blue;
              }
          }
          Response.Write("&lt;script lang='JavaScript'&gt;alert('"+n+"');&lt;/script&gt;");
      }
  </code></pre>
  
  <p>I can access inside repeater but here is the problem: I can't access the last item of repeater. I put that 'n' variable to control how many times I turn inside foreach loop and I see that n always gives -1 of item numbers. For example if I have 3 items in repeater, n is 2, if there is 1 item in repeater, n is 0. What am I doing wrong in here ?</p>
  
  <p>Edit: I am writing my .aspx page since it asked</p>
  
  <pre><code>&lt;asp:Repeater ID="Repeater1" runat="server" DataSourceID="EntityDataSourceTeklifler" OnItemCommand="Repeater1_ItemCommand"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;div class="panel panel-primary"&gt;
                              &lt;div class="panel-body"&gt;
                                  &lt;strong&gt;Teklif No.&lt;/strong&gt;&amp;nbsp;&lt;%#Eval("TeklifId") %&gt;&lt;br /&gt;
                                  &lt;strong&gt;Teklif Tarihi:&lt;/strong&gt;&amp;nbsp;&lt;%#Eval("TeklifTarih") %&gt;&lt;br /&gt;
                                  &lt;strong&gt;Teklifi Hazırlayan:&lt;/strong&gt;&amp;nbsp;&lt;%#Eval("Name") %&gt;&amp;nbsp;&lt;%#Eval("Surname") %&gt;&lt;br /&gt;
                                  &lt;strong&gt;Firma Adı:&lt;/strong&gt;&amp;nbsp;&lt;%#Eval("FirmaAdi") %&gt;&lt;br /&gt;
                                  &lt;strong&gt;Ürünler:&lt;/strong&gt;&lt;br /&gt;
                                  &lt;%#Eval("TeklifSiparis") %&gt;
                                  &lt;strong&gt;Genel Toplam:&lt;/strong&gt;&amp;nbsp;&lt;%#Eval("TeklifTutar") %&gt;$&lt;br /&gt;
                                  &lt;strong&gt;Not:&lt;/strong&gt;&lt;br /&gt;
                                  &lt;%#Eval("TeklifNot") %&gt;&lt;br /&gt;
                                  &lt;strong&gt;Teklif Durumu:&lt;/strong&gt;&amp;nbsp;&lt;asp:Label ForeColor="Red" ID="lblApproved" runat="server" Text='&lt;%# CheckIfApproved(Convert.ToBoolean(Eval("Approved"))) %&gt;'&gt;&lt;/asp:Label&gt;&lt;br /&gt;&lt;br /&gt;
                                  &lt;asp:Button ID="btnAssignApproved" runat="server" Text="Satışa Döndü Olarak İşaretle" CssClass="btn btn-primary" CommandName="Done" CommandArgument='&lt;%# Eval("TeklifId") %&gt;' /&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:Repeater&gt;
  </code></pre>