private int firtv;
private int lastv;
这些需要纪录的变量要设置成static的
private static int firtv;
private static int lastv;
这样值才会在刷新叶面时保留下来

解决方案 »

  1.   

    哈哈,搞定了,多些楼上2位,给分分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 JulBook
    {
    /// <summary>
    /// index 的摘要说明。
    /// </summary>
    public class index : System.Web.UI.Page
    {
    protected System.Data.OleDb.OleDbDataAdapter da;
    protected System.Data.DataSet ds;
    protected System.Web.UI.WebControls.Label info;
    private int pageSize=3;
    public static int fv;
    protected System.Web.UI.WebControls.Button pre;
    protected System.Web.UI.WebControls.Button nex;
    public static int lv;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if(!Page.IsPostBack)
    {
    string sql="select top "+pageSize+" * from julbook order by id desc";
    OpenDb(sql);
    info.Text=fv.ToString()+"&nbsp;&nbsp;&nbsp;&nbsp;"+lv.ToString();
    }
    } private void OpenDb(string sql){
    string path=Request.PhysicalPath;
    path=path.Remove(path.Length-10,10);
    string constr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "julbook.mdb";
    OleDbConnection conn = new OleDbConnection(constr);
    da = new OleDbDataAdapter(sql,conn);
    ds = new DataSet();
    da.Fill(ds,"msg");
    fv=(int)ds.Tables["msg"].Rows[0][0];
    lv=(int)ds.Tables["msg"].Rows[pageSize - 1][0];
    } private void GetD(string direct){
    string sql;
    switch(direct){
    case "nex":
    sql="select top "+pageSize+" * from julbook where id < "+lv+" order by id desc";
    break;
    case "pre":
    sql="select * from(select top "+pageSize+" * from julbook where id > "+fv+" order by id)order by id desc";
    break;
    default:
    sql="select top "+pageSize+" * from julbook order by id desc";
    break;
    }
    OpenDb(sql);
    info.Text=fv.ToString()+"&nbsp;&nbsp;&nbsp;&nbsp;"+lv.ToString();
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.da = new System.Data.OleDb.OleDbDataAdapter();
    this.ds = new System.Data.DataSet();
    ((System.ComponentModel.ISupportInitialize)(this.ds)).BeginInit();
    // 
    // ds
    // 
    this.ds.DataSetName = "NewDataSet";
    this.ds.Locale = new System.Globalization.CultureInfo("zh-CN");
    this.pre.Click += new System.EventHandler(this.pre_Click);
    this.nex.Click += new System.EventHandler(this.nex_Click);
    this.Load += new System.EventHandler(this.Page_Load);
    ((System.ComponentModel.ISupportInitialize)(this.ds)).EndInit(); }
    #endregion private void pre_Click(object sender, System.EventArgs e)
    {
    GetD("pre");
    } private void nex_Click(object sender, System.EventArgs e)
    {
    GetD("nex");
    }