VB.net Gridview分页 跳转后面的页码失败。
小弟刚刚接触VB.net ,在给Gridview分页的时候出现了问题,数据和分页都能看见,但是点后面的页码(比如第2页)不能显示出数据,只有重新执行“ btn1_Click”才会显示第二页,后面的页也是一样的。我这样做有很多页码,能做成只有首页、下一页、上一页、最后一页这样子吗?在最后一页后面显示当前页和一共多少页。
前台代码
<asp:GridView ID="gdvUSB" runat="server" Height="30px" Width="910px" CaptionAlign="Bottom" HorizontalAlign="Center" AllowPaging="True" OnPageIndex="gdvUSB_PageIndexChanging" AllowSorting="True" PageSize="50" >
<RowStyle BackColor="White" BorderStyle="None" BorderWidth="5px" Width="5px" Font-Names="Microsoft YaHei UI" />
<EditRowStyle BackColor="White" BorderStyle="None" />
<HeaderStyle BackColor="White" Font-Names="Microsoft YaHei UI" />
<RowStyle Height="22px" />
</asp:GridView>
后台代码
Protected Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
'Sql Connection information
MMDataAdapter.SelectCommand = New SqlCommand()
MMDataAdapter.SelectCommand.Connection = MMConnection
If Drop1.SelectedIndex = 0 Then
MMDataAdapter.SelectCommand.CommandText = "exec spn " & "'" & txt1.Text & "'" & "Select No as 编号,PN as 料号,Check_MD5 as 校验值,Result as 结果,Size_GB as 光盘大小,ISO_Type as 光盘类型,Remask as 批次 from Alldata"
ElseIf Drop1.SelectedIndex = 1 Then
MMDataAdapter.SelectCommand.CommandText = "exec MD5s " & "'" & txt1.Text & "'" & "Select No as 编号,PN as 料号,Check_MD5 as 校验值,Result as 结果,Size_GB as 光盘大小,ISO_Type as 光盘类型,Remask as 批次 from Alldata"
ElseIf Drop1.SelectedIndex = 2 Then
MMDataAdapter.SelectCommand.CommandText = "exec IFrom " & "'" & txt1.Text & "'" & "Select No as 编号,Project as 项目,PN as 料号,ISO_From as OEM,Ship_Date as 到达时间,Remask as 批次 from Alldata"
End If
MMDataAdapter.SelectCommand.CommandType = CommandType.Text
MMConnection.Open()
MMDataAdapter.Fill(MMDataSet, "Alldata")
MMConnection.Close()
gdvUSB.DataSource = MMDataSet
gdvUSB.DataBind()
MMDataAdapter = Nothing
MMConnection = Nothing
end sub
Protected Sub gdvUSB_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gdvUSB.PageIndexChanging
gdvUSB.PageIndex = e.NewPageIndex
gdvUSB.DataBind()
End Sub