我是菜鸟~~~有时候没人帮忙也是件好事,逼着自己非钻出来不可。唉个中滋味
这样的性能不是很好,但毕竟是可以正常运行的。
当前只做了上一页,下一页,没有判断越界。还望大家多指教~~~
不管怎么说,这个翻页程序没用什么DATAGIRD、DATALIST而是直接在DATASET中就搞定了,主要是通过SQL语句每次抓取一页的记录。页面的布局也更随意了,只需要在调用数据的时候<%=dataset.Tables["table"].Rows[row][clum]%>
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";
Response.Write(fv);
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");
}
}
}