我从 vb.net 开始,我必须制作一个 GridView,它显示来自 sql 查询的寄存器,并在 GridView 上启用了分页。但是分页仅适用于第 1 页中的第一个寄存器,当我单击第 2 页时,它显示的寄存器数量少于应有的数量,并且带有页码的栏消失了。
我见过有类似问题的人,所说的只是:
Protected Sub GridView2_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView2.PageIndexChanging
GridView2.PageIndex = e.NewPageIndex
GridView2.DataBind()
End Sub
但它似乎不起作用。
下面是用两个可能的查询填充 GridView 的代码。如果我禁用分页,它们工作得很好,所以问题不在于查询:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim command As String
command = "SELECT [GVA14]. [COD_CLIENT] As Codigo, [GVA14].[RAZON_SOCI] As Nombre,tabla.[periodo] As Cuota FROM [GVA14] LEFT JOIN (SELECT cod_client as cod_client ,MAX(periodo) as periodo FROM emCuotas GROUP BY cod_client) As tabla ON ([GVA14]. [COD_CLIENT] COLLATE DATABASE_DEFAULT=tabla.[cod_client] COLLATE DATABASE_DEFAULT) ORDER BY [GVA14].[COD_CLIENT]"
Dim dTable As New DataTable
Dim dataAdapter = New OleDbDataAdapter(command, con)
dataAdapter.Fill(dTable)
GridView2.DataSource = dTable
GridView2.DataBind()
nro = 1
End Sub
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim f1 As String
f1 = TextBox1.Text
Dim f2 As String
f2 = TextBox2.Text
Dim command As String
Dim cuantos As Integer = 50
Dim inicio As Integer=0
command = "SELECT COD_CLIENT,RAZON_SOCI,FECHA_ALTA FROM GVA14 WHERE FECHA_ALTA BETWEEN CONVERT(datetime,'" & f1 & "',103) AND CONVERT(datetime,'" & f2 & "',103) Order By COD_CLIENT,FECHA_ALTA"
Dim dTable As New DataTable
Dim dataAdapter = New OleDbDataAdapter(command, con)
dataAdapter.Fill(dTable)
GridView2.DataSource = dTable
GridView2.DataBind()
command = "SELECT Count(FECHA_ALTA) FROM GVA14 WHERE FECHA_ALTA BETWEEN CONVERT(datetime,'" & f1 & "',103) AND CONVERT(datetime,'" & f2 & "',103)"
Dim comand As New Data.OleDb.OleDbCommand(command, con)
Label1.Text = comand.ExecuteScalar
nro=2
End Sub