部分代码如:
AllowPaging="True" 
AllowCustomPaging="True"
BorderStyle="Solid" 
DataKeyField="KeyID" 
AutoGenerateColumns="false" 
PageSize="2" 
CellPadding="0" 
CellSpacing="0" 
AllowSorting="False" 
AlternatingItemStyle-BackColor="#eeeeee" 
HeaderStyle-CssClass="title" 
Width="100%" 
OnPageIndexChanged="objDG_OnPageChange" 
且已经设置了VirtualItemCount的值且值也正确,但在输出显示DataGrid的PageCount时就是1,PageSize的值也正确,不使用自定义分页可以正常分页,但使用自定义分页却不可以。
已经添加了OnPageIndexChanged事件,且已绑定了数据源,

解决方案 »

  1.   

    public void objDG_OnPageChange(object sender, DataGridPageChangedEventArgs e)
    {
    int startIndex ;
    startIndex = dg.CurrentPageIndex * dg.PageSize;
    dg.CurrentPageIndex = e.NewPageIndex;
    this.BindGrid();//自己重新绑定数据
    }
      

  2.   

    查看下OnPageChange事件的委托是不是丢掉了,,
      

  3.   

    //这行必须写在代码里面才可以
    private void ListClassDataGrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
    ListClassDataGrid.CurrentPageIndex = e.NewPageIndex;
    BindData();
    }
      

  4.   

    To: echo123321(LoveDM) 
    这个也写了.
      

  5.   


     
    private void objDG_SelectedIndexChanged(object source,     System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {

    objDG.CurrentPageIndex = e.NewPageIndex;
                                 下两行不是必要的
    oraDA1.Fill(dataSet**);//此句填充dataset,要根据你的需要改
    objDG.DataBind();
    }objDG是你的DataGrid名字,
    一定行
      

  6.   

    private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
    DataGrid1.CurrentPageIndex = e.NewPageIndex;
    ……重新绑定数据……
    }
    这样做一下!
      

  7.   

    建议将数据绑定的Code写成函数 DataGridDataBound(){...}
    Page_Load中增加If Not IsPostBack Then
                DataGridDataBound()
    End If在PageIndexChanged事件中指定
    DataGrid1.CurrentPageIndex = e.NewPageIndex ;
    DataGridDataBound();
    重新进行绑定
      

  8.   

    加入把绑定数据放入BindDataGrid(),
    在Page_Load方法中加入如下判断:
    if (!Page.IsPostBack)
    {
        BindDataGrid();
    }
    在PageIndexChanged事件中加入如下代码:
    DataGrid1.CurrentPageIndex = e.NewPageIndex;
    BindDataGrid();
      

  9.   

    if (!Page.IsPostBack)
    {
        BindDataGrid();
    }
    对,这句很重要,许多datagrid问都出在没有执地这句上.
      

  10.   

    呵呵,各位,现在能显示了,但是在刚开始打开页面的时候,不显示分页链接,当把PagerStyle.Mode的值由NextPrev变成NumericPages的时候,或者两者互换的时候,总之只要开始的时候改变一下PagerStyle.Mode的显示方式,分页的链接就可以显示出来了,而且也可以正常分页,这是什么原因呢?
    Code:
    <asp:DataGrid ID="objDG" AllowPaging="True" AllowCustomPaging="True" BorderStyle="Solid" DataKeyField="KeyID" AutoGenerateColumns="false" CellPadding="0" CellSpacing="0" AllowSorting="False" AlternatingItemStyle-BackColor="#eeeeee" HeaderStyle-CssClass="title" Width="100%" Runat="server">
    <ItemStyle Height="22" />
    <PagerStyle HorizontalAlign="Right" PrevPageText="上一页" NextPageText="下一页" Mode="NextPrev" PageButtonCount="5" CssClass="SplitPage" />if(!Page.IsPostBack)
    {
     this.DataBindSource(1);
     this.objDG.VirtualItemCount = RecordCounts; 
    }protected void objDG_OnPageChange(object s,System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
              CurrentPage = e.NewPageIndex+1;
    this.objDG.CurrentPageIndex = e.NewPageIndex;
    this.DataBindSource(CurrentPage);
    }
      

  11.   

    补充说明:已经在<asp;DataGrid>中设置了PagerStyle-Mode="NextPrev"。
    现在的问题就是数据可以显示,但只能显示第一页的,且没有分页时的链接,但一改变PagerStyle.Mode的值就可以显示了.
      

  12.   

    问题解决了,原来问题出在这里:
    -------------------------------------------------------
    if(!Page.IsPostBack)
    {
     this.DataBindSource(1);
     this.objDG.VirtualItemCount = RecordCounts; 
    }
    -------------------------------------------------------
    将这两句调换一下位置就可以了,因为先绑定数据源,此时的RecordCounts的数据值为0,所以DagaGrid认为其只有一页.
      

  13.   

    看看:pagemodel是什么,num or page