我想实现datagrid分页功能,但每次点下一页,显示的数据都是一样的,请问各位大侠这是怎么回事。vs2003
这是我的源码:
 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not IsPostBack Then
            BindGrid2()
        End If
 Sub BindGrid2()
        Dim cnA As New OleDbConnection
        cnA = New OleDbConnection
        cnA.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Server.MapPath("data/members.mdb")
        cnA.Open()
        Dim mycmd As OleDb.OleDbDataAdapter
        Dim SQLStr2 As String
        SQLStr2 = "SELECT 问题6,问题7,问题8,问题9,问题10 FROM 课程调查2"
        mycmd = New OleDb.OleDbDataAdapter(SQLStr2, cnA)
        Dim dt As Data.DataSet = New Data.DataSet
        mycmd.Fill(dt)
        DataGrid2.DataSource = dt.Tables(0)
        DataGrid2.VirtualItemCount = 200
        DataGrid2.DataBind()
        cnA.Close()
    End Sub
Sub AtPageChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
        DataGrid2.CurrentPageIndex = e.NewPageIndex
        BindGrid2()
    End Sub

解决方案 »

  1.   

    PageIndexChanged事件是否注册,有时候会丢失
      

  2.   

    你没有进行分页,每次都是从数据库里读新的数据,你应该在mycmd.Fill(dt)进行分页处理,如
    sqlDataAdapter.Fill(ds, startRecord, maxRecords, srcTable);写上相应的参数就可以啦。
      

  3.   

    请问PageIndexChanged事件怎么注册哦
    还有请问sqlDataAdapter.Fill(ds, startRecord, maxRecords, srcTable)中参数的意义是什么
      

  4.   

    Sub AtPageChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
            DataGrid2.CurrentPageIndex = e.NewPageIndex
            BindGrid2()
        End Sub怀疑这段代码没被运行
      

  5.   

    private void InitializeComponent()
    {
    this.dgCategory.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.Cancel);//这是我手动加的委托,也就是注册事件
    this.dgCategory.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.Edit);//这也是
    this.dgCategory.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.Update);//这也是
    this.dgCategory.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.Delete);
    this.dgCategory.SelectedIndexChanged += new System.EventHandler(this.Select);
    this.btnDepartment.ServerClick += new System.EventHandler(this.btnDepartment_ServerClick);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion还有你的说那个几个参数
    da.fill(ds,start,size,"table")
    start是开始标记0开头
    size是每次掉多少条数据
      

  6.   

    呵呵,这是datagrid的属性设置,大侠看看有没有问题
    <asp:datagrid id="DataGrid2" style="Z-INDEX: 102; LEFT: 32px; POSITION: absolute; TOP: 216px"
    runat="server" AllowSorting="True" CellPadding="3" BackColor="White" BorderWidth="1px" BorderStyle="None"
    BorderColor="#CCCCCC" AutoGenerateColumns="False" Width="384px" AllowPaging="True" PageSize="2" AllowCustomPaging="True"
    OnPageIndexChanged="AtPageChanged" EnableViewState=True>
      

  7.   

    size是每次提取多少条数据
      

  8.   

    上面的楼主都说正确了,显示问题就是可能没有激发那个PageIndexChanged属性
      

  9.   

    你的PageINdexChanage 事件掉了
      

  10.   

    大侠怎么激发那个PageIndexChanged属性