我试了一下,在DataBind()前加上一行
myDataGrid.DataSource = Session("main4")
就可以啦!你是怎么指定DataSource的?

解决方案 »

  1.   

    http://www.csdn.net/Expert/forum.asp?typenum=8&searchKeys=%B7%D6%D2%B3&roomid=33&author=&tabletype=now
      

  2.   

    to  forever_ares(战神) 
    我就是这样指定datasource的,可是datagrid数据就是不刷新,始终是第一页的数据。
      

  3.   

    to  net_lover(孟子E章)
    论坛里的帖子我早看了个遍,可就是搞不定,所以才来高分求解啊
    谁救救我!!!!!
      

  4.   

    你是使用自定义分页吗??如果是的话还需设置fill的起始地址及页数,不然无论如何都是在第一页
      

  5.   

    to windfun(小宝.NET) 详细说说看,有门
      

  6.   

    datasource还是要指定的,但是列出DataGrid之前要加上判断
    If not ispostback Then...End If
      

  7.   

    to: samuelhs()
    还是不行,难道就没人会吗?????????
      

  8.   

    从这里入手:
    mycommand.fill(main4,"基本表")这样每次按第二页的时候,都只显示0记录到设定的page记录,所以无论如何也只能显示第一页的数据修改为:
    mycommand.fill(main4,数据起始地址,数据结束地址,"基本表")这样就可以了,至于什么是数据起始地址,结束地址可以看看有关的datalist分面例程,其中数据开始地址就是你的当前页,使用myDataGrid.CurrentPageIndex就可得到,另外数据结束地址就是你的pagesize,可以用myDataGrid.PageSize取得,具体做法可以参考一下我的留言簿,我的留言簿下载地址是:http://aspxcn.com
      

  9.   

    重建视图 如下:
    private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
    DataGrid1.DataSource=CreateDataView();
    DataGrid1.CurrentPageIndex=0;
    DataGrid1.CurrentPageIndex=e.NewPageIndex;
    DataGrid1.DataBind();
       }
    //CreateDataView()为建立视图的自定义方法
      

  10.   

    在page_load中
    if not ispostback then
    datasource=table1
    end if
    databind()
    在sub btn_click()中
    session("table1")=table1
    datasource=session("table1")
    databind()没错我的问题就是 这样解决的!
      

  11.   

    我这里有一个翻页的程序,我认为比Datagrid的翻页属性要好一点,大家看看
    Select Case sender.commandargument
                Case "top"
                    DataGrid1.CurrentPageIndex = 0
                    pagenumCount.Text = "當前頁數為" + CStr(DataGrid1.CurrentPageIndex + 1) + "/" + CStr(DataGrid1.PageCount) + "頁"
                    TextBox2.Text = DataGrid1.CurrentPageIndex + 1
                Case "next"
                    If ((DataGrid1.CurrentPageIndex < DataGrid1.PageCount) And (DataGrid1.CurrentPageIndex >= 0)) Then
                        If (DataGrid1.CurrentPageIndex = DataGrid1.PageCount - 1) Then
                            pagenumCount.Text = "當前頁數為" + CStr(DataGrid1.CurrentPageIndex + 1) + "/" + CStr(DataGrid1.PageCount) + "頁"
                        Else
                            DataGrid1.CurrentPageIndex = DataGrid1.CurrentPageIndex + 1
                            pagenumCount.Text = "當前頁數為" + CStr(DataGrid1.CurrentPageIndex + 1) + "/" + CStr(DataGrid1.PageCount) + "頁"
                            TextBox2.Text = DataGrid1.CurrentPageIndex + 1
                        End If
                    End If
                Case "prev"
                    If (DataGrid1.CurrentPageIndex > 0) Then
                        DataGrid1.CurrentPageIndex = DataGrid1.CurrentPageIndex - 1
                        pagenumCount.Text = "當前頁數為" + CStr(DataGrid1.CurrentPageIndex + 1) + "/" + CStr(DataGrid1.PageCount) + "頁"
                        TextBox2.Text = DataGrid1.CurrentPageIndex + 1
                    End If
                Case "last"
                    DataGrid1.CurrentPageIndex = DataGrid1.PageCount - 1
                    pagenumCount.Text = "當前頁數為" + CStr(DataGrid1.CurrentPageIndex + 1) + "/" + CStr(DataGrid1.PageCount) + "頁"
                    TextBox2.Text = DataGrid1.CurrentPageIndex + 1
                Case "cometo"
                    If CInt(TextBox2.Text) >= DataGrid1.PageCount Then
                        DataGrid1.CurrentPageIndex = DataGrid1.PageCount - 1
                        pagenumCount.Text = "當前頁數為" + CStr(DataGrid1.CurrentPageIndex + 1) + "/" + CStr(DataGrid1.PageCount) + "頁"
                    Else
                        If CInt(TextBox2.Text) <= 0 Then
                            DataGrid1.CurrentPageIndex = 0
                            pagenumCount.Text = "當前頁數為" + CStr(DataGrid1.CurrentPageIndex + 1) + "/" + CStr(DataGrid1.PageCount) + "頁"
                        Else
                            DataGrid1.CurrentPageIndex = CInt(TextBox2.Text) - 1
                            pagenumCount.Text = "當前頁數為" + CStr(DataGrid1.CurrentPageIndex + 1) + "/" + CStr(DataGrid1.PageCount) + "頁"
                        End If
                    End If        End Select
            DataGrid1.DataBind()
      

  12.   

    看来在DATAGRID的分页遇到类似问题的不止我一个啊,因为每次点击分页控件,页面都要刷新,这样到DATASET的连接又没了,除了用SESSION,还有别的什么方法么??另外,你说的这个问题我也遇到过,原因是
    if (myDataGrid.CurrentPageIndex>=0 and  myDataGrid.CurrentPageIndex < myDataGrid.PageCount) then
    myDataGrid.CurrentPageIndex =e.NewPageIndex
    《。。此处少了DATASOURCE。。》
             myDataGrid.DataBind ()
    还有,此时的DATABIND其实什么事也没做,如果你把 btn_click 事件中的指定DATAVIEW的代码贴过来,问题就解决了,可是,这样每次都要连数据库,效率又太低,就转到我上面的问题了,哎,我也正发愁呢,因为用SESSION并不是太好,大家也顺便帮我看看啊
      

  13.   

    上述问题我遇到过,已经解决,留下email,我给你源码,但不能保证是最好的。
      

  14.   

    有这么夸张吗?
    在mydatagrid_PageIndexChanged事件的myDataGrid.DataBind()一句前面加上:
    DataSet ds = (DataSet)session("main4")
    myDataGrid.DataSource = ds.Tables("基本表")try it.