Paging a DataList
By Norman Deschauwer**  webform1.cs  ***************************************using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace datalist
{
 /// <summary>
 /// Summary description for WebForm1.
 /// </summary>
 public class WebForm1 : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.DataList DataList1;
  protected System.Web.UI.WebControls.TextBox TextBox1;
  protected System.Web.UI.WebControls.TextBox TextBox2;
  protected System.Web.UI.WebControls.LinkButton LinkButton1;
  protected System.Web.UI.WebControls.LinkButton LinkButton2;
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   if(!IsPostBack)
   {
    TextBox1.Text="0";
    TextBox2.Text="1";
    Build_List();
   }
  }
  private void Build_List()
  {
   try
   {
    string dsn = "Provider=SQLOLEDB;uid=uid;pwd=pwd;server=servername;database=dbname";
    OleDbConnection ocon = new OleDbConnection(dsn);
    ocon.Open();
    string strsql="select * from personne";
                OleDbDataAdapter oda = new OleDbDataAdapter(strsql,ocon);
    DataSet ods = new DataSet();
    int index = int.Parse(TextBox1.Text);    
    oda.Fill(ods,index,1,"contact");    
    DataList1.DataSource=ods.Tables["contact"].DefaultView;
    DataList1.DataBind();
    ocon.Close();   }
   catch(Exception ex)
   {
    Response.Write(ex.Message+"  "+ex.StackTrace);
   }
  }  #region Web Form Designer generated code
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: This call is required by the ASP.NET Web Form Designer.
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {    
   this.LinkButton1.Click += new System.EventHandler(this.LinkButton1_Click);
   this.LinkButton2.Click += new System.EventHandler(this.LinkButton2_Click);
   this.Load += new System.EventHandler(this.Page_Load);  }
  #endregion  private void LinkButton1_Click(object sender, System.EventArgs e)
  {
   int index = int.Parse(TextBox1.Text);
   index--;
   TextBox1.Text= index.ToString();
   Build_List();
  }  private void LinkButton2_Click(object sender, System.EventArgs e)
  {
   int index = int.Parse(TextBox1.Text);
   index++;
   TextBox1.Text= index.ToString();
   Build_List();  }
 }
}*** end webform1.cs ********************************************
*** webform1.aspx **********************************************<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="datalist.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
 <HEAD>
  <title>WebForm1</title>
  <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
  <meta name="CODE_LANGUAGE" Content="C#">
  <meta name="vs_defaultClientScript" content="JavaScript">
  <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
 </HEAD>
 <body MS_POSITIONING="GridLayout">
  <form id="Form1" method="post" runat="server">
   <table border="1">
    <TBODY>
     <tr>
      <td><asp:DataList id="DataList1" runat="server" Visible="True">
        <HeaderTemplate>
        </HeaderTemplate>
        <ItemTemplate>
         nom :
         <%# DataBinder.Eval(Container.DataItem , "lastname")%>
         <br>
         prenom :
         <%# DataBinder.Eval(Container.DataItem, "firstname")%>
         <br>
         date de naissance :
         <%# DataBinder.Eval(Container.DataItem, "dob")%>
         <br>
        </ItemTemplate>
        <FooterTemplate>
        </FooterTemplate>
       </asp:DataList></td>
     </tr>
     <tr>
      <td><asp:LinkButton id="LinkButton1" runat="server">precedent</asp:LinkButton>
       <asp:LinkButton id="LinkButton2" runat="server">suivant</asp:LinkButton></td>
     </tr>
     <tr>
      <td><asp:TextBox id="TextBox1" runat="server"></asp:TextBox></td>
     </tr>
     <tr>
      <td><asp:TextBox id="TextBox2" runat="server"></asp:TextBox></td>
     </tr>
     <tr>
      <td></td>
     </tr>
    </TBODY>
   </table>
  </form>
 </body>
</HTML>