VB.net Gridview分页 跳转后面的页码失败。

zxdpxl 2015-09-26 10:39:28
小弟刚刚接触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

...全文
221 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

16,547

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧