title: Issues with custom DataPager
body: <p>I am trying to extend the asp.net <code>DataPager</code> control into a custom control with predefined templates. This is the desired output</p>
  
  <p><img src="https://i.stack.imgur.com/hXcwc.gif" alt="enter image description here"></p>
  
  <p><strong>Problems</strong>: </p>
  
  <ol>
  <li>When I load the page containing the custom DataPager for the first time, the <code>SelectMethod</code> of my <code>ObjectDataSource</code> is called 3 times.</li>
  <li>When I try to load another page of data using the DataPager, the SelectMethod is called twice.</li>
  <li>When I try to load another page of data, either by using the Next/Previous buttons or the DropDownList, the page does not change. I ran some debugging and found that it was not passing the correct value to the StartRowIndexParameter of the SelectMethod (it just passed 0 everytime it called the method). </li>
  </ol>
  
  <p>Here's the code for my custom control.</p>
  
  <pre><code>public class DataPagerDDL : DataPager
  {
      protected override void RenderContents(HtmlTextWriter writer)
      {
          //add custom template
          TemplatePagerField templateField = new TemplatePagerField();
          templateField.PagerTemplate = new CustomTemplate();
          Fields.Add(templateField);
  
          //add previous/next page template
          NextPreviousPagerField nextPreviousField = new NextPreviousPagerField();            
          nextPreviousField.ShowFirstPageButton = false;
          nextPreviousField.ShowLastPageButton = false;
          nextPreviousField.PreviousPageText = "&lt;&lt;";
          nextPreviousField.NextPageText = "&gt;&gt;";
          Fields.Add(nextPreviousField);
  
          base.RenderContents(writer);
      }
  
      public void cmbPage_SelectedIndexChanged(object sender, EventArgs e)
      {
          DropDownList cmbPage = (DropDownList)sender;
          this.SetPageProperties(cmbPage.SelectedIndex * MaximumRows, MaximumRows, true);
      }
  }
  
  public class CustomTemplate : ITemplate
  {
      /// &lt;summary&gt;
      /// Insert an instance of text and controls into the specified container.
      /// &lt;/summary&gt;
      public void InstantiateIn(Control container)
      {
          DataPagerFieldItem caller = (DataPagerFieldItem)container;
          DataPagerDDL pager = (DataPagerDDL)caller.Parent;
          int totalPages = pager.TotalRowCount / pager.MaximumRows;
          if (pager.TotalRowCount % pager.MaximumRows &gt; 0) totalPages += 1;
          int currentPage = (pager.StartRowIndex / pager.MaximumRows) + 1;
  
          DropDownList cmbPage = new DropDownList();
          cmbPage.ID = "cmbPage";
          cmbPage.AutoPostBack = true;
          cmbPage.SelectedIndexChanged += new EventHandler(pager.cmbPage_SelectedIndexChanged);
          for (int i = 1; i &lt;= totalPages; i++)
          {
              ListItem item = new ListItem(i.ToString(), i.ToString());
              if (i == currentPage) item.Selected = true;
              cmbPage.Items.Add(item);
          }
  
          pager.Controls.Add(new LiteralControl("Page "));
          pager.Controls.Add(cmbPage);
          pager.Controls.Add(new LiteralControl(" of " + totalPages.ToString() + " pages | "));
      }
  }
  </code></pre>
  
  <p>And this is what my page looks like:</p>
  
  <pre><code>&lt;asp:ListView ID="ListView1" DataSourceID="ods1" ... &gt;
  ...
  &lt;/asp:ListView&gt;
  
  &lt;custom:DataPagerDDL ID="CustomDataPager" runat="server" PagedControlID="ListView1" 
          PageSize="25"&gt;
  &lt;/custom:DataPagerDDL&gt;    
  
  &lt;asp:ObjectDataSource ID="ods1" ... &gt;
  &lt;/asp:ObjectDataSource&gt;
  </code></pre>
  
  <p>What should I do to make my custom DataPager work as intended? Thanks in advance! :)</p>