datagrid启用修改后,对textbox修改为什么无法获得修改后的值?
datagrid启用修改后,对textbox修改,为什么无法获得修改后的值?
Dim NumCols As Integer = E.Item.Cells.Count
Dim CurrentTextBox As TextBox
Dim ColValue As String
CurrentTextBox = E.Item.Cells(2).Controls(0)
ColValue = CurrentTextBox.Text
还是未得到修改的值!!================================================================
Sub MyDataGrid_Update(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)
Dim myconn As OleDb.OleDbConnection = New OleDbConnection("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=works;Data Source=.")
Dim zw As String
Dim bmzyzs As String
Dim ids As String
Dim NumCols As Integer = E.Item.Cells.Count
Dim CurrentTextBox As TextBox
Dim ColValue As String
CurrentTextBox = E.Item.Cells(2).Controls(0)
ColValue = CurrentTextBox.Text
Response.Write(ColValue)
Response.End()
' 检查在所需字段中是否有空值
If ColValue = "" Then
Label1.Text = "错误:""职务""不允许使用空值"
Label1.Style("color") = "red"
Return
Else
zw = ColValue
End If
CurrentTextBox = E.Item.Cells(3).Controls(0)
ColValue = CurrentTextBox.Text
' 检查在所需字段中是否有空值
If ColValue = "" Then
Label1.Text = "错误:""部门重要指数""不允许使用空值"
Label1.Style("color") = "red"
Return
Else
bmzyzs = ColValue
End If
ColValue = MyDataGrid.DataKeys(CInt(E.Item.ItemIndex))
' 检查在所需字段中是否有空值
If ColValue = "" Then
Label1.Text = "错误:""ID""不允许使用空值"
Label1.Style("color") = "red"
Return
Else
ids = ColValue
End If
Dim UpdateCmd As String = "UPDATE 公司职务 SET 职务='" + zw + "',部门重要指数=" + bmzyzs + " where 编号 = " + ids
Dim MyCommand As OleDbCommand = New OleDbCommand(UpdateCmd, myconn)
MyCommand.Connection.Open()
Try
MyCommand.ExecuteNonQuery()
Label1.Text = "已更新记录" & UpdateCmd.ToString()
MyDataGrid.EditItemIndex = -1
BindGrid()
Catch Exp As OleDbException
Label1.Text = "错误:未能更新记录,请确保正确填写了字段" + Exp.Source + Exp.Message
Label1.Style("color") = "red"
End Try
MyCommand.Connection.Close()
End Sub