急求救一个Datagrid分页问题大虾速来.....
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