title: paging in datalist using javascript
body: <p>iam trying to use paging for my datalist using following code...iam able to do it server side but how can i do it client side..i mean iam already binding my datalist on page load..alli need is to allow paging on client side</p>
  
  <p>aspx</p>
  
  <pre><code>&lt;asp:LinkButton ID="LinkButton3" runat="server" CommandName="Previous" Text="&lt;&lt; Previous"
                              OnClick="Pager_Click"&gt;&lt;/asp:LinkButton&gt;
                          &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                          &lt;input id="Button6" type="button" value="close" onclick="Hidee2()" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                          &lt;asp:LinkButton ID="LinkButton4" runat="server" CommandName="Next" Text="Next &gt;&gt;"
                              OnClick="Pager_Click"&gt;&lt;/asp:LinkButton&gt;
  </code></pre>
  
  <p>coodebhind</p>
  
  <pre><code>private int CurrentPage = 1;
          private int ItemsPerPage = 4;
  
  
   protected void Page_Load(object sender, EventArgs e)
          {
  
  int TotalRows = this.BindList(1);
                  this.Prepare_Pager(TotalRows);
  }
  
  
  
  //this binds the datalist
  
   private int BindList(int PageNo)
          {
              int TotalRows = 0;
              DataTable dt = new DataTable();
              SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["DSN"]);
              SqlDataAdapter sda = new SqlDataAdapter();
              SqlCommand cmd = new SqlCommand("spx_Pager");
              cmd.CommandType = CommandType.StoredProcedure;
              cmd.Parameters.Add("@PageNo", SqlDbType.Int).Value = PageNo;
              cmd.Parameters.Add("@ItemsPerPage", SqlDbType.Int).Value = ItemsPerPage;
              cmd.Parameters.Add("@TotalRows", SqlDbType.Int).Direction = ParameterDirection.Output;
              cmd.Connection = con;
              try
              {
                  con.Open();
                  sda.SelectCommand = cmd;
                  sda.Fill(dt);
                  DataList1.DataSource = dt;
                  DataList2.DataSource = dt;
                  DataList3.DataSource = dt;
                  DataList4.DataSource = dt;
  
                  DataList1.DataBind();
                  DataList2.DataBind();
                  DataList3.DataBind();
                  DataList4.DataBind();
                  TotalRows = Convert.ToInt32(cmd.Parameters["@TotalRows"].Value);
              }
              catch (Exception ex)
              {
                  Response.Write(ex.Message);
              }
              finally
              {
                  con.Close();
                  sda.Dispose();
                  con.Dispose();
              }
              return TotalRows;
          }
  
  
  //This prepaes pager for my datalist
  
          private void Prepare_Pager(int TotalRows)
          {
              int intPageCount = this.CalculateTotalPages(TotalRows);
              if (intPageCount &gt; 1 &amp;&amp; this.CurrentPage &lt; intPageCount)
              {
                  this.lnkNext.Enabled = true;
              }
              if (this.CurrentPage != 1)
              {
                  this.lnkPrev.Enabled = true;
              }
              else
              {
                  this.lnkPrev.Enabled = false;
              }
          }
  
  
  //This is managing my pager click events for pervious and next link buttons above
  
  
  protected void Pager_Click(object sender, EventArgs e)
          {
              LinkButton lnkPager = (LinkButton)sender;
              int PageNo = 1;
              switch (lnkPager.CommandName)
              {
                  case "Previous":
                      PageNo = this.CurrentPage - 1;
                      break;
                  case "Next":
                      PageNo = this.CurrentPage + 1;
                      break;
              }
              int TotalRows = this.BindList(PageNo);
              int PageCount = this.CalculateTotalPages(TotalRows);
              ViewState["CurrentPage"] = PageNo;
              if (PageNo == 1)
              {
                  lnkPrev.Enabled = false;
              }
              else
              {
                  lnkPrev.Enabled = true;
              }
              if (PageNo == PageCount)
              {
                  lnkNext.Enabled = false;
              }
              else
              {
                  lnkNext.Enabled = true;
              }
          }
  </code></pre>