就是每次搜索这前都要回到第一页搜索才不会出错
我试过用在Button的Onclick时将CurrenPageIndex置0,但是不行,在DataGrid1_PageIndexChanged之分页又会出错

解决方案 »

  1.   

    点击搜索后先
    DataGrid1.CurrentPageIndex = 0;

    搜索的代码
      

  2.   

    不是在Click事件里设置CurrenPageIndex置0,而应该在你搜索后重新帮定DataGrid的时候设置CurrenPageIndex置0
      

  3.   

    to:
    bitliuyang(昊天) 这样的话,点第2页怎么搞?
      

  4.   

    这种情况我也遇到过 ,可以在填充datagird 代码加如下代码
     Dim numPage As Int32 = Int(dv.Count / DataGrid1.PageSize)
                If numPage * DataGrid1.PageSize < dv.Count Then
                    numPage += 1
                End If
                If numPage < 1 Then numPage = 1
                If DataGrid1.CurrentPageIndex > numPage - 1 Then
                    DataGrid1.CurrentPageIndex = numPage - 1
                End If
    然后在分页代码中调用,请楼主试一试
    Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
            Me.DataGrid1.CurrentPageIndex = e.NewPageIndex
            End Sub
      

  5.   

    可以设置一个标识符,用页面级的ViewState["Flag"]=0
    当你搜索时,把ViewState["Flag"]=1
    在绑定的时候判断
    if(int.Parse(ViewState["Flag"]==1))//也就是搜索的时候
    {
    DataGrid1.CurrentPageIndex=0;//设置为0,是因为你搜索后的总页数没有当前页的页数大,而导致会出现  无效的 CurrentPageIndex 值。它必须大于等于 0 且小于 PageCount这个错误
    }
    搜索时候,马上把ViewState["Flag"]的值设置为0在你的绑定事件中判断
      

  6.   

    问题已经解决了,是参考Xiangying621(英) 的来写的,sunnystar365还没有试过,有空再试一下。
    安安和昊天的我试过都不行,不知道是什么地方出了问题
    总之谢谢各位啦