title: Getting control from Repeater ItemTemplate server-side
body: <p>I'm trying to use a repeater to make a table. however, there's some logic that I need to implement to some specific controls, says a div, in the items in the repeater.</p>
  
  <p>I've tried <a href="https://stackoverflow.com/questions/3293739/repeater-itemtemplate-server-side">this</a> but it didn't work,,, <strong>I alwas get:</strong></p>
  
  <blockquote>
    <p>Exception Details: System.NullReferenceException: Object reference not
    set to an instance of an object.</p>
    
    <p>Source Error:</p>
  </blockquote>
  
  <pre><code>Line 35:         HtmlGenericControl myDiv = (HtmlGenericControl)e.Item.FindControl("RepeaterBG");
  Line 36: 
  Line 37:         myDiv.Style.Add("background-color","green");
  Line 38:     }
  Line 39: }
  </code></pre>
  
  <blockquote>
    <p>Description: An unhandled exception occurred during the execution of
    the current web request. Please review the stack trace for more
    information about the error and where it originated in the code.</p>
  </blockquote>
  
  <p><strong>My Html is:</strong></p>
  
  <pre><code>&lt;asp:Repeater runat="server" ID="MyStudents"
          OnItemDataBound="rptArticleContent_ItemDataBound"&gt;
              &lt;HeaderTemplate&gt;
                  &lt;table&gt;&lt;tr&gt;
              &lt;/HeaderTemplate&gt;
              &lt;ItemTemplate&gt; 
  
                  &lt;td&gt;
                      &lt;div  runat="server" ID="RepeaterBG" &gt; helli there&lt;/div&gt;
                      &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Bind("Name") %&gt;'&gt;&lt;/asp:Label&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:Label ID="Label2" runat="server" Text='&lt;%# Bind("RegistrationDate") %&gt;'&gt;&lt;/asp:Label&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:Label ID="Label3" runat="server" Text='&lt;%# Bind("Email") %&gt;'&gt;&lt;/asp:Label&gt;
                  &lt;/td&gt;
  
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;/tr&gt;&lt;/table&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:Repeater&gt;
  </code></pre>
  
  <p><strong>my .CS</strong></p>
  
  <pre><code>protected void rptArticleContent_ItemDataBound(object sender, RepeaterItemEventArgs e)
  {
      Label lb = new Label();
      lb.Text = "&lt;/tr&gt;&lt;tr&gt;";
      e.Item.Controls.Add(lb);
  
      HtmlGenericControl myDiv = (HtmlGenericControl)e.Item.FindControl("RepeaterBG"); // i get null here, it seems to not find it at all!
      myDiv.Style.Add("background-color","green"); // problem here
  }
  </code></pre>
  
  <p>where did i go wrong?!</p>