public partial class _Default : System.Web.UI.Page{
 
    static string constr = "Data Source=.;Initial Catalog=KCSJ;User ID=sa;password=123";
    SqlConnection con = new SqlConnection(constr);
    protected void Page_Load(object sender, EventArgs e)
    {
      
      con.Open();  
      SqlDataAdapter da = new SqlDataAdapter();  
      da.SelectCommand = new SqlCommand("SELECT * FROM yongju",con);
      DataSet ds = new DataSet();
      da.Fill(ds);
      //对PagedDataSource 对象的相关属性赋值
      PagedDataSource objPage = new PagedDataSource();
      objPage.DataSource = ds.Tables[0].DefaultView;
      //允许分页 
      objPage.AllowPaging = true;
      //设置每页显示的项数 
      objPage.PageSize =6;
      //定义变量用来保存当前页索引 
      int CurPage;
      //判断是否具有页面跳转的请求 
      if (Request.QueryString["yongju"] != null)
          CurPage = Convert.ToInt32(Request.QueryString["yongju"]);
      else
          CurPage = 1;
      //设置当前页的索引 
      objPage.CurrentPageIndex = CurPage - 1;
      // 显示状态信息 
      this.lblCurPage.Text = "当前页:第" + CurPage.ToString() + "页";
      //如果当前页不是首页 
      if (!objPage.IsFirstPage)
          //定义“上一页”的超级连接URL为:当前执行页面的虚拟路径,并传递下一页面的索引值。 
          this.HyperLink1.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);       if (!objPage.IsLastPage)
          //定义“下一页”的超级连接URL为:当前执行页面的虚拟路径,并传递下一页面的索引值。 
          this.HyperLink2.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);       //进行数据绑定 
      this.DataList1.DataSource = objPage;
      this.DataList1.DataBind();
      
  }