很抱歉可能有重复的问题,但我对此感到很疯狂!
我有一个asp gridview(gvResults),它根据用户选择从sql查询中动态设置其数据集。这是asp grideview代码:
<asp:GridView ID="gvResults" runat="server" Visible="False" BorderColor="White" BorderWidth="1px" CssClass="gvClass" AllowPaging="True" HorizontalAlign="Left" OnPageIndexChanging="gvResults_PageIndexChanged" AllowSorting="True" ShowFooter="True">
这是sql查询背后的VB.NET代码之一,它将数据放入数据表中,然后将其绑定到网格视图:
Dim dt As New DataTable()
Dim connString As String = "Data Source=SQL5\AX;Initial Catalog=PAR;User ID=XXXXX;Password=XXXXXXXXX"
Dim connection As New SqlConnection(connString)
Dim cmd As New SqlCommand("Select current_status as Status, Count(current_status) As Total From tbl_PAR_Management Where current_status !='Closed' Group By current_status")
Dim sqlDa As New SqlDataAdapter(cmd)
cmd.Connection = connection
connection.Open()
sqlDa.Fill(dt)
gvResults.DataSource = dt
gvResults.DataBind()
connection.Close()
以下是我用来尝试和寻找下一组结果的内容:
Protected Sub gvResults_PageIndexChanged(ByVal sender As Object, e As GridViewPageEventArgs)
gvResults.PageIndex = e.NewPageIndex
gvResults.DataBind()
End Sub
我的问题是当我点击第2页或任何其他页码时,网格视图关闭,我看不到查询的任何结果。发生这种情况我错过了什么或做错了什么?
提前感谢您的帮助。
答案 0 :(得分:0)
您正在gvResults_PageIndexChanged
中调用您的代码。
尝试将代码放入gvResults_PageIndexChanging
。