aspnetpager分页数据库为access
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
protected void bind()
{
String Zl = Request.QueryString["zlname"].ToString();
string sqlstr = "select * from y_newnr inner join (select * from y_newlm )as a on a.lmid=y_newnr.lmid where zlname='" + Zl + "'";
OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
PagedDataSource ps = new PagedDataSource();
OleDbDataAdapter da = new OleDbDataAdapter(sqlstr, conn);
DataSet ds = new DataSet();
da.Fill(ds, "y_newnr");
ps.DataSource = ds.Tables["y_newnr"].DefaultView;
AspNetPager1.RecordCount = ps.Count;
ps.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
ps.AllowPaging = true;
ps.PageSize = AspNetPager1.PageSize;
GridView1.DataSource = ps;
GridView1.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
bind();
}
这个能查出对应的数据出来,可是Aspnetpager就是不显示,绑定这里被我弄的乱七八糟的了
在本论坛搜索了一个源码,但是我不会写AccessHelper,各位哥哥们能帮帮小弟写个绑定或者AccessHelper.cs吧,谢谢!
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();
} access 分页 aspnetpager
[解决办法]
看不出问题
你是多少数据一页
调试一下全部有多少条
[解决办法]
那就是打开数据库并执行查询输出结果集的一个操作类 你的代码里不是已经有写嘛 你封装一下不就可以了
[解决办法]
DataTable result = new DataTable();
PagedDataSource pds = new PagedDataSource();
result = BLL.GetResult(); //获取数据
AspNetPager1.RecordCount = result.Rows.Count;
pds.AllowPaging = true;
pds.PageSize = AspNetPager1.PageSize;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
pds.DataSource = result.DefaultView;
gvResult.DataSource = pds;
gvResult.DataBind();