急求救一个Datagrid分页问题大虾速来.....

MouseClick 2007-06-18 11:13:08
datagrid自定义分页功能.点击第二页正常.编辑的时候就跑到第一页了.不知道怎么解决..
代码:
Dim cn As New SqlConnection("server=.;database=testDb;uid=sa")
Dim rowCount As Integer
Dim startIndex As Integer
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
DataGridDataBind()
End If
End Sub
Private Sub DataGridDataBind()
Try

Dim da As New SqlDataAdapter("select bookName,UnitsInStock,UnitPrice,bookID,book.publishID,bookImg,book.CategoryID,bookBrief,auther,CategoryName,publishName from book,Categories,publish where book.CategoryID=Categories.CategoryID and book.publishID=publish.publishID", cn)
Dim ds As New DataSet
cn.Open()
da.Fill(ds, startIndex, DataGrid1.PageSize, "book") '指定索引开始取记录
da.Fill(ds, "AllDataTable")
DataGrid1.VirtualItemCount = ds.Tables("AllDataTable").Rows.Count ' 获取自定义实际页数
DataGrid1.DataSource = ds.Tables("book")
rowCount = ds.Tables("book").Rows.Count
DataGrid1.DataBind()
Catch ex As Exception
Response.Write(ex.Message)
Finally
cn.Close()
End Try
End Sub
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
'编辑

DataGrid1.EditItemIndex = e.Item.ItemIndex
Label1.Text = DataGrid1.CurrentPageIndex
btnSelect.Enabled = False
DataGridDataBind()
End Sub
Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.CancelCommand
'取消
DataGrid1.EditItemIndex = -1
DataGridDataBind()
btnSelect.Enabled = True
End Sub
Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex
startIndex = DataGrid1.PageSize * DataGrid1.CurrentPageIndex
DataGridDataBind()
End Sub
...全文
169 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Jinglecat 2007-06-19
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
'编辑

DataGrid1.EditItemIndex = e.Item.ItemIndex
Label1.Text = DataGrid1.CurrentPageIndex
btnSelect.Enabled = False
DataGridDataBind()
End Sub
============
1。编辑事件处理程序调用 DataGridDataBind() 的时候,startIndex 并未正确赋值,应该是你的初始值 0, 导致 da.Fill(ds, startIndex, DataGrid1.PageSize, "book") 从第一页开始加载数据

》》》

btnSelect.Enabled = False
startIndex = DataGrid1.PageSize * DataGrid1.CurrentPageIndex
DataGridDataBind()
回复
相关推荐
发帖
.NET技术社区
创建于2007-09-28

5.8w+

社区成员

.NET技术交流专区
申请成为版主
帖子事件
创建了帖子
2007-06-18 11:13
社区公告
暂无公告