AspNetPager分页控件和access怎么用 我的数据库是access的但是我想用AspNetPager来实现分页,请问各位怎样实现这个功能?谢谢了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 AspNetPager控件是独立的http://topic.csdn.net/u/20100224/16/0205b8b6-3a15-4c78-8be1-ea072be26b53.html 我用过AspNetPager和直接绑定三层代码中的方法的,没用过 Access 可动态生成分页sql代码再调aspnetpager,有许多较成熟的类,google下 access 里面是不允许出现0 的。select top (pageSize) * from table where table_id not in(select top (pageIndex-1)*pageSize table_id from table)也就是说top 后面不能允许出现0 .其他的就和其他的数据库一样的用法了。 Access不支持存储过程,所以一般只能用多重select语句选择当页数据或返回全部数据后再分页,AspNetPager的示例项目中有相关例子。 protected void bind() { string sql = "select * from news"; string con = AccessHelper.conn; PagedDataSource ps = new PagedDataSource(); ps.DataSource = AccessHelper.ExecuteDataSet(con, sql).Tables[0].DefaultView; AspNetPager1.RecordCount = ps.Count; ps.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1; ps.AllowPaging = true; ps.PageSize = AspNetPager1.PageSize; DataList1.DataSource = ps; DataList1.DataBind(); } protected void AspNetPager1_PageChanged(object sender, EventArgs e) { bind(); } PagedDataSource pds = new PagedDataSource(); DataTable dt = nbll.GetList("").Tables[0]//这里换成你的数据源; this.AspNetPager1.RecordCount = dt.Rows.Count; pds.DataSource = dt.DefaultView; pds.AllowPaging = true; pds.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1; pds.PageSize = this.AspNetPager1.PageSize; this.Repeater1.DataSource = pds; this.Repeater1.DataBind();接下来这个一定要写,找到AspNetPager的PageChanged事件protected void AspNetPager1_PageChanged(object sender, EventArgs e){ bind();//调用数据绑定的方法,也就是上面的方法} 那access怎么才能达到页面无刷新分页呢? 1、在工具栏添加——选择项——选择AspNetPager.dll控件2、把控件AspNetPager拖到设计页面3、在后台页码添加修改代码4、在前台双击AspNetPager控件的onpagechanged事件,在后台加载数据代码加载过程后台代码如下://创建数据库的连结对象 OleDbConnection objCon = new OleDbConnection(); //设置连接字符串 objCon.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + @"|DataDirectory|\示例.mdb"; //打开数据库 objCon.Open(); //创建数据执行命令对象主要是针对分页控件进行的命令操作 OleDbCommand objCom = new OleDbCommand(); //以上面建立的数据库连接进行关联 objCom.Connection = objCon; //设置数据库命令的方式 objCom.CommandType = CommandType.Text; //设置数据执行命令////////////////////////////////////////////////////////////////以下代码是获取数据库记录数,计算分页页码 objCom.CommandText = "select Count(*) from 订单";//Count(*)是获取表的记录数,也叫聚合函数 AspNetPager1.RecordCount = Convert.ToInt32(objCom.ExecuteScalar()); int pageIndex = AspNetPager1.CurrentPageIndex - 1; int pageSize = AspNetPager1.PageSize;/////////////////////////////////////////////////////////////分页结束 //创建数据执行命令对象 OleDbCommand cmd = new OleDbCommand(); cmd.Connection = objCon; cmd.CommandText = "select * from 订单"; //创建数据适配器对象 OleDbDataAdapter objDa = new OleDbDataAdapter(); //适配器对应的命令对象 objDa.SelectCommand = cmd; //创建数据集对象 DataSet objDS = new DataSet(); //填充数据集 //分页控件也需要填充数据集,其中,pageIndex ,pageSize, 就是分页控件的索引和页码 objDa.Fill(objDS, pageIndex * pageSize, pageSize, "订单"); Repeater1.DataSource = objDS; Repeater1.DataBind(); PetShop3.0 是什么? (C#)导入EXCEL文件时,如何取得工作表的名称。 验证问题! 关于验证控件的问题 在web应用程序中,是全部页面共享一个Sqlconnection好呢,还是每个页面逗建立一个SqlConnection好 B/S 架构下打印的实现--在线等待,立即给分 关于ASP.NET WEB页面打印的问题. 求asp.net视频生成技术 请问这三本书怎么样? 请问如何在DATAGRIE的EDIT里得到某个值? repeater数据绑定 webservice 数缓存
http://topic.csdn.net/u/20100224/16/0205b8b6-3a15-4c78-8be1-ea072be26b53.html
也就是说top 后面不能允许出现0 .其他的就和其他的数据库一样的用法了。
{
string sql = "select * from news";
string con = AccessHelper.conn;
PagedDataSource ps = new PagedDataSource();
ps.DataSource = AccessHelper.ExecuteDataSet(con, sql).Tables[0].DefaultView;
AspNetPager1.RecordCount = ps.Count;
ps.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
ps.AllowPaging = true;
ps.PageSize = AspNetPager1.PageSize;
DataList1.DataSource = ps;
DataList1.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
bind();
}
DataTable dt = nbll.GetList("").Tables[0]//这里换成你的数据源;
this.AspNetPager1.RecordCount = dt.Rows.Count;
pds.DataSource = dt.DefaultView;
pds.AllowPaging = true;
pds.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;
pds.PageSize = this.AspNetPager1.PageSize;
this.Repeater1.DataSource = pds;
this.Repeater1.DataBind();接下来这个一定要写,找到AspNetPager的PageChanged事件protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
bind();//调用数据绑定的方法,也就是上面的方法
}
那access怎么才能达到页面无刷新分页呢?
2、把控件AspNetPager拖到设计页面
3、在后台页码添加修改代码
4、在前台双击AspNetPager控件的onpagechanged事件,在后台加载数据代码加载过程后台代码如下:
//创建数据库的连结对象
OleDbConnection objCon = new OleDbConnection();
//设置连接字符串
objCon.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + @"|DataDirectory|\示例.mdb";
//打开数据库
objCon.Open(); //创建数据执行命令对象主要是针对分页控件进行的命令操作
OleDbCommand objCom = new OleDbCommand();
//以上面建立的数据库连接进行关联
objCom.Connection = objCon;
//设置数据库命令的方式
objCom.CommandType = CommandType.Text;
//设置数据执行命令////////////////////////////////////////////////////////////////以下代码是获取数据库记录数,计算分页页码
objCom.CommandText = "select Count(*) from 订单";//Count(*)是获取表的记录数,也叫聚合函数 AspNetPager1.RecordCount = Convert.ToInt32(objCom.ExecuteScalar()); int pageIndex = AspNetPager1.CurrentPageIndex - 1;
int pageSize = AspNetPager1.PageSize;
/////////////////////////////////////////////////////////////分页结束
//创建数据执行命令对象
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = objCon;
cmd.CommandText = "select * from 订单"; //创建数据适配器对象
OleDbDataAdapter objDa = new OleDbDataAdapter();
//适配器对应的命令对象
objDa.SelectCommand = cmd; //创建数据集对象
DataSet objDS = new DataSet(); //填充数据集
//分页控件也需要填充数据集,其中,pageIndex ,pageSize, 就是分页控件的索引和页码
objDa.Fill(objDS, pageIndex * pageSize, pageSize, "订单"); Repeater1.DataSource = objDS;
Repeater1.DataBind();