比如说我用datalist控件来显示数据库,因为内容过多涉及到分页听说AspNetPager不错,很方便,但就是不知道如何用请问在后台代码里要做如何设置:    protected void Page_Load(object sender, EventArgs e)
    {        string strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath ("db1.mdb");
        OleDbConnection ConnAcc=new OleDbConnection (strConn); 
        ConnAcc.Open ();
        string strSQL="SELECT * FROM wzw_client"; 
        OleDbDataAdapter da=new OleDbDataAdapter(strSQL,ConnAcc); 
        DataSet ds=new DataSet();
        da.Fill(ds,"wzw");
        ConnAcc.Close ();        wzwList.DataSource = ds;  //设置数据源 
        wzwList.DataBind();       //绑定数据
    }

解决方案 »

  1.   

    PageDataSource
    官方网上有说明!
    不过建议用存储过程比较好!
      

  2.   

    www.webdiyer.com
    去这里看看..
      

  3.   

    官方网上有说明! 
    www.webdiyer.com 
      

  4.   


    protected void GV_Bind()//绑定控件
            {
                Guid id = new Guid(departid);
                DataCollection<DepartInfo3SDO> depart3Collection = getDepart3Service().FindByParentID(id);
                AspNetPager1.RecordCount = depart3Collection.Count;
                PagedDataSource pds = new PagedDataSource();
                pds.DataSource = depart3Collection;
                pds.AllowPaging = true;
                pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
                pds.PageSize = AspNetPager1.PageSize;
                GV_DepartInfo3.DataSource = pds;
                GV_DepartInfo3.DataBind();
            } protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
            {
                AspNetPager1.CurrentPageIndex = e.NewPageIndex;
                GV_Bind();
            }
      

  5.   

    http://www.webdiyer.com 下载页面有详细的示例代码可以下载,你上面的代码中,应该改为这样: protected void Page_Load(object sender, EventArgs e) 
        {
        if(!IsPostBack){
            string strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath ("db1.mdb"); 
            OleDbConnection ConnAcc=new OleDbConnection (strConn); 
            OleDbCommand cmd=new OleDbCommand("SELECT count(*) FROM wzw_client",ConnAcc); 
    ConnAcc.Open();
    AspNetPager1.RecordCount=(int)cmd.ExecuteScalar(); //设置总记录数
    ConnAcc.Close();
    bindData(); 绑定当前页数据
        }
        }    void bindData(){
            string strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath ("db1.mdb"); 
            OleDbConnection ConnAcc=new OleDbConnection (strConn); 
            string strSQL="SELECT * FROM wzw_client"; 
            OleDbDataAdapter da=new OleDbDataAdapter(strSQL,ConnAcc); 
            DataSet ds=new DataSet(); 
            da.Fill(ds,AspNetPager1.StartRecordIndex-1,AspNetPager1.PageSize,"wzw");  //只填充当前页的数据
            wzwList.DataSource = ds;  //设置数据源 
            wzwList.DataBind();      //绑定数据 
        }    然后编写PageChanged事件处理程序,在该处理程序中重新调用 bindData()方法就行了。
      

  6.   

    webdiyer 用户,好样的,找的就是这个答案,谢谢了
      

  7.   

    其实ObjectDataSource本身支持分页的。不信你看一下他的属性栏里有一个EnablePaing(这个和GridView的EnablePaing不是一回事)。再结合Sql Server2005的ROW_NUMBER(),可以不用AspNetPager。通过ObjectDataSource进行分页关键还是存储过程,也就是只取回需要的那一页的数据。大概的格式:
    create procedure XXXProc
    (
        @startRowIndex int,
        @maximumRows int
    )
    as
    select columnList from (select columnList, ROW_NUMBER() OVER (ORDER BY orderColumn) as RowRank) AS TableWithRowNumbers
    where RowRank > @startRowIndex and RowRank <= (@startRowIndex + @maximumRows)数据访问层通过这个存储过程提供数据给业务逻辑层,另外再向业务逻辑层提供一个返回数据总数的接口(select count(*) from table)。业务逻辑层建一个能接受startRowIndex, maximumRows为参数的方法来调用数据访问层对应的方法,该方法又调用上面这个存储过程。
    再建一个调用数据访问层返回的数据总数的方法。配置ObjectDataSource的SelectCountMethod,再把向导生成的ObjectDataSource的<SelectParameters>段去掉(因为GridView会自动向ObjectDataSource传递startRowIndex, maximumRows值)。大概也就这样了。
      

  8.   

    同意7楼的说法
    void bindData(){ 
            string strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath ("db1.mdb"); 
            OleDbConnection ConnAcc=new OleDbConnection (strConn); 
            string strSQL="SELECT * FROM wzw_client"; 
            OleDbDataAdapter da=new OleDbDataAdapter(strSQL,ConnAcc); 
            DataSet ds=new DataSet(); 
            da.Fill(ds,AspNetPager1.StartRecordIndex-1,AspNetPager1.PageSize,"wzw");  //只填充当前页的数据 
            wzwList.DataSource = ds;  //设置数据源 
            wzwList.DataBind();      //绑定数据 
        }