gridview手动绑定数据后分页异常
代码如下ProtectedSubButton1_Click(ByValsenderAsObject,ByValeAsEventArgs)HandlesButton1.Cl...
代码如下
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
GridView1.AllowPaging = True
GridView1.PageSize = 4
Dim MyCon As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("data1.mdb")) '创建连接对象
Dim SQLStr2 As String = "Select nr,tyr,tysj,zrr,jhwc,sjwc From table1 where tyr='肖满';" '设置SQL命令字符串
Dim sda As New OleDbDataAdapter(SQLStr2, MyCon)
Dim dt As New DataSet
sda.Fill(dt, "table1")
GridView1.DataSource = dt.Tables("table1").DefaultView
GridView1.DataBind()
sda.Dispose()
dt.Dispose()
MyCon.Close()
MyCon.Dispose()
End Sub
Private Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
GridView1.DataBind()
End Sub
点击页码后GridView1无任何显示。求解决办法,如果需要再绑定一个数据源,代码要如何改动呢? 展开
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
GridView1.AllowPaging = True
GridView1.PageSize = 4
Dim MyCon As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("data1.mdb")) '创建连接对象
Dim SQLStr2 As String = "Select nr,tyr,tysj,zrr,jhwc,sjwc From table1 where tyr='肖满';" '设置SQL命令字符串
Dim sda As New OleDbDataAdapter(SQLStr2, MyCon)
Dim dt As New DataSet
sda.Fill(dt, "table1")
GridView1.DataSource = dt.Tables("table1").DefaultView
GridView1.DataBind()
sda.Dispose()
dt.Dispose()
MyCon.Close()
MyCon.Dispose()
End Sub
Private Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
GridView1.DataBind()
End Sub
点击页码后GridView1无任何显示。求解决办法,如果需要再绑定一个数据源,代码要如何改动呢? 展开
展开全部
GridView1_PageIndexChanging时间里面传递了e.NewPageIndex值以后要重新调用绑定方法
包含查询数据
GridView1.DataSource = dt.Tables("table1").DefaultView
GridView1.DataBind()
不是直接重新调用GridView1.DataBind()就行的。
包含查询数据
GridView1.DataSource = dt.Tables("table1").DefaultView
GridView1.DataBind()
不是直接重新调用GridView1.DataBind()就行的。
追问
太吊,太强大啦,问题解决了。
偶像,我已经是你忠实的粉了,留个QQ我吧
我的Q是386026965
顺便问问,用vb2008写asp页面时,怎么声明全局变量啊?网上有人说用cookie但是以前我没用过....能否指点一下或者有什么其他更好的方法?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询