急急急!!!!!!!!添加页码模式和数字模式后那里的编辑(更新,取消)不能打开了
Function CreateDataSet(ByVal strSQL As String, ByVal FileName As String, ByVal TableName As String) As DataSetDim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(FileName)
Dim objCmd As New OleDbDataAdapter(strSQL, ConnString)
Dim DS As New DataSet
objCmd.Fill(DS, TableName)
CreateDataSet = DS
End Function
Sub BindList()
DataGrid1.DataSource = CreateDataSet("select * from book", "Mydb.mdb", "book")
DataGrid1.DataBind()
End Sub
Public Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then BindList()
If RadioButton1.Checked Then
DataGrid1.PagerStyle.Mode = PagerMode.NextPrev
DataGrid1.PagerStyle.PrevPageText = "上一页"
DataGrid1.PagerStyle.NextPageText = "下一页"
Else
DataGrid1.PagerStyle.Mode = PagerMode.NumericPages
End If
BindList()
End Sub
Sub DataGrid_EditCommand(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
DataGrid1.EditItemIndex = e.Item.ItemIndex
BindList()
End Sub
Sub DataGrid_CancelCommand(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
DataGrid1.EditItemIndex = -1
BindList()
End Sub
Private Sub DataGrid1_UpdateCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
Dim aa As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
Dim bb As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Dim cc As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text
Dim dd As String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
Dim strSQL As String
strSQL = "Update book Set 代号= ' " & aa & " ', 刊名=' " & bb & " ', 类别=' " & cc & " ',刊期=' " & dd & " ' Where " & DataGrid1.DataKeyField & "=" & DataGrid1.DataKeys(e.Item.ItemIndex)
Dim objConn As New OleDbConnection
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("Mydb.mdb")
objConn.Open()
Dim objCmd As New OleDbCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
DataGrid1.EditItemIndex = -1
BindList()
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
BindList()
End Sub
End Class
[[it] 本帖最后由 twtdd 于 2008-6-15 01:25 编辑 [/it]]