DataGrid只有上一页,下一页,没有第一页,最后一页等,所以我用PagedDataSource定义自己的分页形式:
共多少页||每页显示几条||第一页||上一页||下一页||尾页但是我想用形如DataGrid中的数据编辑那种修改数据的方式,因为只有DataGrid有这个功能,所以我把DataGrid跟自己定义的分页绑定在一块又因为夹杂了一个数据库操作类,结果乱套了,好郁闷阿,不知道大家是怎么做这块的,能否指教一下,如何去做,我看我同学里面有数据编辑和分页显示兼得的,但是我不知道他用的什么控件,我笨了点,请大家帮帮忙啊?给个思路

解决方案 »

  1.   

    大哥,你说说思路,你用的也是DataGrid控件来数据编辑的么?
      

  2.   

    粘个我写的代码,你参考一下吧。
    //PagedDataSource是控制分页的类,在System.Web.UI.WebControls空间里。
    PagedDataSource objPds=new PagedDataSource();
    //da是数据源,是一个DataTable。
    objPds.DataSource=da.DefaultView;
    objPds.AllowPaging=true;
    //下面设置每页的条数
    objPds.PageSize=Convert.ToInt32(ConfigurationSettings.AppSettings["QuestionPageSize"]);
    int curPage;
    if(Request.QueryString["page"]!=null)
    {
    int theCurPage=Convert.ToInt32(Request.QueryString["page"]);
    if(theCurPage<1)
    curPage=1;
    else if(theCurPage>objPds.PageCount)
    curPage=objPds.PageCount;
    else
    curPage=theCurPage;
    } else
    curPage=1;
    //设置当前的页数
    objPds.CurrentPageIndex=curPage-1;
    设置页面上显示的当前页数
    currentPage.Text=curPage.ToString();
    设置页面上攻多少页的显示。
    pageCount.Text=objPds.PageCount.ToString();
    //设置上一页链接是否可用,以及具体链接。
    if(!objPds.IsFirstPage)
    {
    prePage.Enabled=true;
    prePage.NavigateUrl=Request.CurrentExecutionFilePath+"?classID="+Request.QueryString["classID"].ToString()+"&page="+Convert.ToString(curPage-1);
    }
    //设置下一页链接是否可用,以及具体链接。
    if(!objPds.IsLastPage)
    {
    nextPage.Enabled=true;
    nextPage.NavigateUrl=Request.CurrentExecutionFilePath+"?classID="+Request.QueryString["classID"].ToString()+"&page="+Convert.ToString(curPage+1);
    }
    //设置转到第几页的下拉列表里的项。
    for(int i=0;i<objPds.PageCount;i++)
    {
    ListItem newItem=new ListItem((i+1).ToString(),(i+1).ToString());
    changePage.Items.Add(newItem);
    }
    //设置本页的DataGrid的数据源为objPds并绑定。
    this.QuestionDL.DataSource=objPds;
    另外,你需要为转到第几页的下拉列表的选项改变事件写一个方法:
    public void changeThePage(object sender, System.EventArgs e)
    {
    Response.Redirect(Request.CurrentExecutionFilePath+"?classID="+Request.QueryString["classID"].ToString()+"&page="+Convert.ToString(changePage.SelectedItem.Value.ToString()));
    }
    this.QuestionDL.DataBind();
      

  3.   

    上面这样只是把DataGrid的数据源变了一下,其它的就碍不着DataGrid的事了。