title: ASP.NET Repeater has a null value
body: <p>I'm using ASP.NET Repeater for dynamically generating HTML code and pagination. I use totally same code on two aspx pages and on one all works fine, but on the other one I get an Exception: Object reference not set to an instance of an object.</p>
  
  <p><img src="https://i.stack.imgur.com/URmqe.png" alt="enter image description here"></p>
  
  <p>Now I understand why the exception occurred, it simply has a null value, repeater didn't render I guess. But does anyone know why this error happened and how it's possible that it works on one page, and doesn't work on the other? Where should I look for "real" problem?</p>
  
  <p>This is my HTML code on the aspx page:</p>
  
  <pre><code>&lt;div class="accordion-wrap projects"&gt;
  &lt;asp:Repeater runat="server" ID="projectRepeter"&gt;
  &lt;ItemTemplate&gt;
  
      &lt;div class="item"&gt;
          &lt;div class="heading"&gt;
              &lt;span&gt;
                  &lt;asp:Label runat="server" ID="TeamMemberName" Text='&lt;%#Eval("ProjectName")%&gt;'&gt;&lt;/asp:Label&gt;&lt;/span&gt;&lt;span&gt;&lt;em&gt;x&lt;/em&gt;&lt;/span&gt;
              &lt;i&gt;+&lt;/i&gt;
          &lt;/div&gt;
          &lt;div class="details"&gt;
              &lt;ul class="form"&gt;
                  &lt;li&gt;
                      &lt;label&gt;Project name:&lt;/label&gt;
                      &lt;input type="text" class="in-text" value="&lt;%#Eval("ProjectName")%&gt;" /&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                      &lt;label&gt;Lead:&lt;/label&gt;
                      &lt;asp:DropDownList runat="server" DataSourceID="TeamMemberNameDS"&gt;&lt;/asp:DropDownList&gt;
                  &lt;/li&gt;
              &lt;/ul&gt;
              &lt;ul class="form"&gt;
                  &lt;li&gt;
                      &lt;label&gt;Description:&lt;/label&gt;
                      &lt;input type="text" class="in-text" value="&lt;%#Eval("Description")%&gt;" /&gt;
                  &lt;/li&gt;
              &lt;/ul&gt;
              &lt;ul class="form last"&gt;
                  &lt;li&gt;
                      &lt;label&gt;Customer:&lt;/label&gt;
                      &lt;asp:DropDownList runat="server" DataSourceID="ClientNameDS"&gt;&lt;/asp:DropDownList&gt;
                  &lt;/li&gt;
                  &lt;li class="inline"&gt;
                      &lt;label&gt;Status:&lt;/label&gt;
                      &lt;span class="radio"&gt;
                          &lt;label for="inactive"&gt;Active:&lt;/label&gt;
                          &lt;input type="radio" value="1" name="status" id="inactive" /&gt;
                      &lt;/span&gt;
                      &lt;span class="radio"&gt;
                          &lt;label for="active"&gt;Inactive:&lt;/label&gt;
                          &lt;input type="radio" value="2" name="status" id="active" /&gt;
                      &lt;/span&gt;
                      &lt;span class="radio"&gt;
                          &lt;label for="active"&gt;Archive:&lt;/label&gt;
                          &lt;input type="radio" value="3" name="status" id="Radio1" /&gt;
                      &lt;/span&gt;
                  &lt;/li&gt;
              &lt;/ul&gt;
              &lt;div class="buttons"&gt;
                  &lt;div class="inner"&gt;
                      &lt;a href="javascript:;" class="btn green"&gt;Save&lt;/a&gt;
                      &lt;a href="javascript:;" class="btn red"&gt;Delete&lt;/a&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/ItemTemplate&gt;
  &lt;/asp:Repeater&gt;
  &lt;/div&gt;
  &lt;div class="pagination"&gt;
  &lt;asp:Repeater ID="rptPagingProject" runat="server" OnItemCommand="rptPaging_ItemCommand"&gt;
  &lt;ItemTemplate&gt;
      &lt;asp:LinkButton ID="btnPage"
          CommandName="Page" CommandArgument="&lt;%# Container.DataItem %&gt;" runat="server" ForeColor="Black" Font-Bold="True"&gt;&lt;%# Container.DataItem %&gt;
      &lt;/asp:LinkButton&gt;
  &lt;/ItemTemplate&gt;
  &lt;/asp:Repeater&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And this is the code behind:</p>
  
  <pre><code>protected void BindRepeater()
  {
      string ConnectionString = "Data Source=PRACTICE-001;Initial Catalog=n.mosorinski;User ID=n.mosorinski;Password=n.mosorinski;MultipleActiveResultSets=True;Application Name=EntityFramework";
      SqlConnection con = new SqlConnection(ConnectionString);
      SqlCommand cmd = new SqlCommand("SELECT p.ProjectName, p.Description, c.ClientName FROM Project AS p INNER JOIN Client AS c ON p.CustomerID = c.ClientID", con);
      if (con.State == ConnectionState.Closed)
      {
          con.Open();
      }
      DataTable dt = new DataTable();
      SqlDataAdapter adp = new SqlDataAdapter(cmd);
      adp.Fill(dt);
      PagedDataSource pgitems = new PagedDataSource();
      DataView dv = new DataView(dt);
      pgitems.DataSource = dv;
      pgitems.AllowPaging = true;
      pgitems.PageSize = 5;
      pgitems.CurrentPageIndex = PageNumber;
  
      if (pgitems.PageCount &gt; 1)
      {
          rptPagingProject.Visible = true;
          ArrayList pages = new ArrayList();
          for (int i = 0; i &lt; pgitems.PageCount; i++)
              pages.Add((i + 1).ToString());
          rptPagingProject.DataSource = pages;
          rptPagingProject.DataBind();
      }
      else
      {
          rptPagingProject.Visible = false;
      }
      projectRepeter.DataSource = pgitems;
      projectRepeter.DataBind();
  }
  
  public int PageNumber
  {
      get
      {
          if (ViewState["PageNumber"] != null)
              return Convert.ToInt32(ViewState["PageNumber"]);
          else
              return 0;
      }
      set
      {
          ViewState["PageNumber"] = value;
      }
  }
  
  protected void rptPaging_ItemCommand(object source, RepeaterCommandEventArgs e)
  {
      PageNumber = Convert.ToInt32(e.CommandArgument) - 1;
      BindRepeater();
  }
  </code></pre>
  
  <p>}</p>