急求datagrid 分页问题
我想实现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
------解决方案--------------------PageIndexChanged事件是否注册,有时候会丢失
------解决方案--------------------你没有进行分页,每次都是从数据库里读新的数据,你应该在mycmd.Fill(dt)进行分页处理,如
sqlDataAdapter.Fill(ds, startRecord, maxRecords, srcTable);写上相应的参数就可以啦。
------解决方案--------------------Sub AtPageChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
DataGrid2.CurrentPageIndex = e.NewPageIndex
BindGrid2()
End Sub
怀疑这段代码没被运行
------解决方案--------------------private void InitializeComponent()
{
this.dgCategory.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.Cancel);//这是我手动加的委托,也就是注册事件
this.dgCategory.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandl