title: Determine current page without using the DataPager's QueryString (ListView ASP.NET)
body: <p>I have a Tab Control that contains a ListView, there are three Tabs, each tab contains the same ListView but the Data Source is changed whenever the tab chagnes.</p>
  
  <p>Lets say there are 3 Tabs:
  Tab1: Customers
  Tab2: Items
  Tab3: Orders</p>
  
  <p>The problem comes when I use a DataPager. (<strong>Previous</strong> 1 2 3 4 5 6 ... <strong>Next</strong>)
  The DataPager uses a QueryString:</p>
  
  <pre><code>&lt;asp:DataPager runat="server" ID="DataPager1" PagedControlID="ListView1" PageSize="5"     QueryStringField="page"  OnPreRender="Pager_PreRender" &gt;
      &lt;Fields&gt;
          &lt;asp:NextPreviousPagerField ButtonType="Button" PreviousPageText="Previous" /&gt;
          &lt;asp:NumericPagerField ButtonType="Link" ButtonCount="10" /&gt;
          &lt;asp:NextPreviousPagerField ButtonType="Button" NextPageText="Next" /&gt;
      &lt;/Fields&gt;
  &lt;/asp:DataPager&gt;
  </code></pre>
  
  <p>This produces the following URL:</p>
  
  <p>http:// localhost /MyProject/view/Customers?page=1</p>
  
  <p>Lets say I'm in <strong>Tab3: Orders</strong>, if I navigate to the next Page a postback occurs and <strong>Tab1: Customers</strong> is displayed instead and that is because the URL indicates <strong>view/Customers?page=1</strong> 
  Is there anyway to achieve paging without using the QueryString?</p>
  
  <p>Here is where I use the QueryString:</p>
  
  <pre><code>    protected void Pager_PreRender(object sender, EventArgs e)
      {
          int CurrentPage = 0;
          Int32.TryParse(Request.QueryString["page"], out CurrentPage);
          CurrentPage = CurrentPage.Equals(0) ? 1 : CurrentPage;
  
          HyperLink PreviousLink = DataPager1.Controls[0].Controls[0] as HyperLink;
          HyperLink NextLink = DataPager1.Controls[2].Controls[0] as HyperLink;
          if (PreviousLink != null)
          {
              if (CurrentPage.Equals(1))
              {
                  PreviousLink.Visible = false;
              }
              else if (CurrentPage &gt; 1)
              {
                  PreviousLink.Visible = true;
              }
          }
          if (NextLink != null)
          {
              if ((CurrentPage * DataPager1.PageSize) &gt;= DataPager1.TotalRowCount)
              {
                  NextLink.Visible = false;
              }
              else
              {
                  NextLink.Visible = true;
              }
          }
      }
  </code></pre>