得写个公共涵数!System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
这里错误!

解决方案 »

  1.   

    tingningpower(听宁) :能否具体一些?如何写公共函数?
    多谢!
                                                         小弟这厢有礼.
      

  2.   

    private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    { DataGrid1.CurrentPageIndex=e.NewPageIndex;
    BindData();//重新绑定
    }
      

  3.   

    你可能已经转到第3页,然后再重新搜索,而重新搜索的结果如果没有3页,就会报错。
    解决的办法是:DataGrid1.CurrentPageIndex = 0
    首先设定datagrid1的页数为第一页,但是你要注意,翻页的时候,不能执行这个语句,只有在重新执行查询的时候才执行。
      

  4.   

    做一个判断,翻页之前看看pageindex是否大于pagecount
      

  5.   

    你应该将绑定数据源的整个过程写成一个独立的函数,包括建立连接,建立dataadapter, 填充dataset, 绑定到datagrid。
    然后在page_load和datagrid1_pageindexchanaged()事件中调用。
      

  6.   

    casear_huang(落叶飞舞):
    chenbinghui(阿炳): 
    两位仁兄,小弟先行谢过。在断点跟踪时发现:
    DataGrid1.CurrentPageIndex=e.NewPageIndex;
    之前,DataGrid1.CurrentPageIndex已经为零,我尝试在查询时将
    DataGrid1.CurrentPageIndex=0;无效!spring_ok(SpringDotNet):
    我尝试写过自己定义的函数以实现数据绑定,使用系统自已生成的:protected System.Data.OleDb.OleDbConnection oleDbConnection1;
    protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
    protected System.Data.OleDb.OleDbCommand oleDbCommand1;
    protected BGWeb.DataSet1 dataSet12;
    protected System.Web.UI.WebControls.DataGrid DataGrid1;
    protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
    依然出错。我当如何?
    求救中。                                                  小弟这厢有礼
     
      

  7.   

    spring_ok(SpringDotNet):
    请稍后,容我再试一下。
    多谢关照。 
                                                小弟这厢有礼!
      

  8.   

    int startIndex;
    void ChangePage(Object sender, DataGridPageChangedEventArgs e) 
      {    
          startIndex = e.NewPageIndex*Grid1.PageSize;
          Grid1.CurrentPageIndex = e.NewPageIndex;
          BindGrid();
      }
      

  9.   

    mwpg79(深蓝的海):  老兄,岂能光说不练?
      闻道有先后,术业有专攻,程序员当互相学习,以助人为己乐,岂是嘲弄他人而后快?  请老兄赐教:
      1、DataGrid查询、排序后可实现正常分页?
      2、如何使用:
         protected System.Data.OleDb.OleDbConnection oleDbConnection1;
         protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
         protected System.Data.OleDb.OleDbCommand oleDbCommand1;
         protected BGWeb.DataSet1 dataSet12;
         protected System.Web.UI.WebControls.DataGrid DataGrid1;
         protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
         (系统自定义)     实现数据绑定。
      3、不自已书写数据绑定函数,只使用
         DataGrid.DataBind();可以吗达到我的要求吗。
      虚心请教。                                                       小弟这厢有礼
       
      

  10.   

    If d1.CurrentPageIndex < 0 Then
                    d1.CurrentPageIndex = 0
                Else
                    If d1.CurrentPageIndex > d1.PageCount Then
                        d1.CurrentPageIndex = d1.PageCount
                    Else
                        d1.CurrentPageIndex = e.NewPageIndex
                    End If
                End If
    d1.databind
    d1为datagrid,我用的是vb,你转换为c#即可,看看结果如何,应该是你加了
    限制条件以后,在改变条件时出来错误了
      

  11.   

    int indexsum;
                indexsum=dataplan.CurrentPageIndex;
    dataplan.CurrentPageIndex=0;
    dataplan.DataBind();
    dataplan.CurrentPageIndex=indexsum;
    if (indexsum>dataplan.PageCount-1)
    {
    dataplan.CurrentPageIndex--;
    dataplan.DataBind();
    }
    else
    {
    dataplan.DataBind();
    }
    需要DataBind()两次
      

  12.   

    lulu_zz(luluer),luofix(枯古)二位兄台:我已如老兄所说绑定,依然无效。
    5555555555555555555555555555
    求助中。
                                   小弟这厢有礼。
    lulu_zz(luluer) ://换页
    if (DataGrid1.CurrentPageIndex< 0) 
       DataGrid1.CurrentPageIndex=0;
       else
         if (DataGrid1.CurrentPageIndex>DataGrid1.PageCount-1) 
         DataGrid1.CurrentPageIndex=DataGrid1.PageCount-1;
                      else
                   DataGrid1.CurrentPageIndex=e.NewPageIndex;
    DataGrid1.DataBind();
    luofix(枯古):
    DataGrid1.CurrentPageIndex=0;
                DataGrid1.DataBind();

    if (DataGrid1.CurrentPageIndex>DataGrid1.PageCount-1) 
    {
    DataGrid1.CurrentPageIndex=DataGrid1.PageCount-1;
                    DataGrid1.DataBind();
    } DataGrid1.CurrentPageIndex=e.NewPageIndex;
    DataGrid1.DataBind();
      

  13.   

    MSDN上面有例程,自己可以看看,如果实在不行,我给你发一代码。
      

  14.   

    to:mwpg79:
    什么风格不风格,
    程序员就是解决问题,问题解决了就好,
    我真看不惯你这样的!
      

  15.   

    startIndex = e.NewPageIndex*Grid1.PageSize;
          Grid1.CurrentPageIndex = e.NewPageIndex;
          BindGrid();
      

  16.   

    在查询按钮事件里应该把DataGrid的CurrentPageIndex 设为1就行了。