DataGrid分页时用AspNetPager ,显示数据不全。为什么?

解决方案 »

  1.   

    以下是我的代码,大家帮忙看看<webdiyer:aspnetpager id="AspNetPager1" runat="server" Width="100%" HorizontalAlign="center" ShowInputBox="always"
    SubmitButtonStyle="border:1px solid #000066;height:20px;width:30px" InputBoxStyle="border:1px #0000FF solid;text-&#13;&#13;&#10;align:center"
    CssClass="mypager" TextBeforeInputBox="转到第" TextAfterInputBox="页" AlwaysShow="True" NumericButtonCount="20" FirstPageText="首页"
    NextPageText="下一页" PrevPageText="上一页" LastPageText="尾页" SubmitButtonText="Go"></webdiyer:aspnetpager>private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if(!Page.IsPostBack)
    {
    BindData();
    }
    }protected void BindData()
    {
    string connStr = "server=.;database=softwaremanage;uid=sa;pwd=sa";//设定数据库连接字符串
    SqlConnection conn = new SqlConnection(connStr);//连接数据库
    conn.Open();//打开数据库
    string sql = "select * from SoftwareInfo";
    SqlCommand comm = new SqlCommand(sql, conn);
    SqlDataAdapter da = new SqlDataAdapter(comm);
    DataSet ds = new DataSet();
    da.Fill(ds, "SoftwareInfo");

    PagedDataSource pds = new PagedDataSource();
    pds.DataSource = ds.Tables[0].DefaultView;//设置分页的数据源
    pds.AllowPaging = true;//设置允许分页
    AspNetPager1.RecordCount = pds.Count;//AspNetPager1.RecordCount = ds.Tables[0].DefaultView.Count;等价//获取数据的条数
    pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;//设置当前页的索引
    pds.PageSize = AspNetPager1.PageSize;//设置每页显示的页数
    this.DataGrid.DataSource = pds;
    this.DataGrid.DataBind();//绑定数据
    }public void AspNetPager1_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
    {
    AspNetPager1.CurrentPageIndex = e.NewPageIndex;
    BindData();

    }
      

  2.   

    SqlCommand comm = new SqlCommand(sql, conn);
                SqlDataAdapter da = new SqlDataAdapter(comm);换成
    SqlDataAdapter da = new SqlDataAdapter(sql, conn);
      

  3.   

    http://www.cnblogs.com/jembai/archive/2008/09/23/1296899.html
      

  4.   

    你说的数据不全是什么不全,是不是应该是10条,确显示了8条?
    看看你的dataGrid 里和AspNetPager1的PageSize属性.
      

  5.   

    http://www.cnblogs.com/yangtu86/archive/2006/06/27/436897.html
      

  6.   

    //注意下面这句,只填充当前页要显示的数据,不能把所有数据全填充到DataSet中,否则无法实现分页
    da.Fill(ds,pager.PageSize*(pager.CurrentPageIndex-1),pager.PageSize,"newtable");