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

解决方案 »

  1.   


    我总共8条数据,我设置成PageSize="4",另外4条就被它吃了,没了,aspnetpager控件也没显示
      

  2.   

    最上面那个是我抄别人的,东拼西凑出来的,不好使啊。能查数据不能分页。
    下面这段代码也是别人写的,应该是OK的,能把其中的AccessHelper用上面的代码替换了吗,新手不会用类啊
      

  3.   

    PagedDataSource  这个我没用过 建议写个分页存储过程吧
      

  4.   


    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();
      

  5.   

    麻烦把BLL.GetResult();这个换成直接的代码好吗
      

  6.   

    说实话,这个问题白问了,自己还是解决了/
    protected void bindData()
        {
             
            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 + "'";
             this.AccessDataSource1.DataFile="E:/dgwz/data/db1.mdb";
            this.AccessDataSource1.SelectCommand=sqlstr;
            PagedDataSource pds = new PagedDataSource();
            pds.AllowPaging = true;
            pds.PageSize = AspNetPager1.PageSize;
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
            DataView dv = (DataView)AccessDataSource1.Select(DataSourceSelectArguments.Empty);
            pds.DataSource = dv;
            GridView1.DataSource = pds;
            GridView1.DataBind();
            
        }    protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            bindData();
        }    protected void AccessDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
        {
            AspNetPager1.RecordCount = e.AffectedRows;
        }