title: How do I connect an ObjectDataSource, a ListView and a DataPager?
body: <p>When I try to connect together an ObjectDataSource, a ListView and a DataPager, the correct values are not passed to the select method of the ObjectDataSource. -1 is always passed for <code>maximumRows</code> and 0 is passed for <code>startRowIndex</code>.</p>
  
  <pre><code>&lt;asp:DataPager runat="server" ID="Address_DataPager" PageSize="50" PagedControlID="Address_ListView" &gt;
      &lt;Fields&gt;
          &lt;asp:NextPreviousPagerField ShowFirstPageButton="true" ShowLastPageButton="true"
              FirstPageText="|&amp;lt;&amp;lt; " LastPageText=" &amp;gt;&amp;gt;|"
              NextPageText=" &amp;gt; " PreviousPageText=" &amp;lt; " /&gt;
      &lt;/Fields&gt;
  &lt;/asp:DataPager&gt;
  &lt;asp:ListView ID="Address_ListView" runat="server"
      DataSourceID="Address_DataSource" DataKeyNames="AddressId" &gt;
      &lt;LayoutTemplate&gt;
          &lt;table class="resultsGrid"&gt;
              &lt;tr class="gridRow"&gt;
                  &lt;th scope="col"&gt;Address&lt;/th&gt;
              &lt;/tr&gt;
              &lt;asp:PlaceHolder ID="itemPlaceholder" runat="server" /&gt;
          &lt;/table&gt;
      &lt;/LayoutTemplate&gt;
      &lt;ItemTemplate&gt;
          &lt;tr class="gridRow"&gt;
              &lt;td&gt;
                  &lt;asp:Label ID="Address_Label" runat="server" Text='&lt;%# Eval("Address") %&gt;' /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/ItemTemplate&gt;
  &lt;/asp:ListView&gt;
  &lt;asp:ObjectDataSource ID="Address_DataSource" runat="server" TypeName="SuperApp.Business.Address"
      SelectMethod="SelectAddress" EnablePaging="True"
      MaximumRowsParameterName="maximumRows"
      StartRowIndexParameterName="startRowIndex" &gt;
      &lt;SelectParameters&gt;
          &lt;asp:Parameter Name="maximumRows"   DefaultValue="10" Type="Int32" /&gt;
          &lt;asp:Parameter Name="startRowIndex" DefaultValue="5"  Type="Int32" /&gt;
      &lt;/SelectParameters&gt;
  &lt;/asp:ObjectDataSource&gt;
  </code></pre>
  
  <p>This is the select method in the <code>Address</code> class in the <code>SuperApp.Business</code> namespace:</p>
  
  <pre><code>System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
  public DataTable SelectAddress(int maximumRows, int startRowIndex)
  {
      if (maximumRows &lt; 1) throw new ArgumentOutOfRangeException("maximumRows", "Maximum rows should be greater than zero.");
      if (startRowIndex &lt; 0) throw new ArgumentOutOfRangeException("startRowIndex", "Start row index should be greater or equal to zero.");
      if (startRowIndex &gt;= maximumRows) throw new ArgumentOutOfRangeException("startRowIndex", "Start row index should be less than the maximum rows.");
  
      // Would do something interesting here.
      return null;
  }
  </code></pre>
  
  <p>The first exception is always thrown, as <code>maximumRows</code> is always -1. I have tried:</p>
  
  <ul>
  <li>Moving the DataPager into the LayoutTemplate.</li>
  <li>Moving the DataPager into the LayoutTemplate and removing the PagedControlID value.</li>
  <li>Changing the DefaultValue values to all sorts of things.</li>
  <li>Removing the DefaultValues from the Parameters.</li>
  <li>Removing the Type from the Parameters.</li>
  <li>Removing the SelectParameters completely.</li>
  </ul>
  
  <p>It is probably something obvious that I just can't see. Any suggestions?</p>