DataGrid问题:编辑以后如何更新?

fbysss 2003-09-11 10:40:59
DataGrid1_EditCommand中编辑的代码:
DataGrid1.EditItemIndex = e.Item.ItemIndex;
DataGrid1.DataBind();
我希望不通过写SQL语句,达到更新的效果,同时DATAGRID也刷新数据。
...全文
73 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
caojingui 2004-03-08
  • 打赏
  • 举报
回复
不用sql,就用RecordSet更新
xj1122 2004-03-08
  • 打赏
  • 举报
回复
上面是.vb中的代码,在.aspx中加入OleDbDataAdapter1,还有dataset1.employee,自己慢慢研究吧,msdn中有的~!
xj1122 2004-03-08
  • 打赏
  • 举报
回复
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
Dim fName, lName As String

' Gets the value of the key field of the row being updated
' Dim key As String = DataGrid1.DataKeys(e.Item.ItemIndex).ToString()
Dim key As String
Try
key = DataGrid1.DataKeys(e.Item.ItemIndex).ToString()
Catch
key = DataGrid1.DataKeys(0).ToString()

End Try

' Gets get the value of the controls (textboxes) that the user
' updated. The DataGrid columns are exposed as the Cells collection.
' Each cell has a collection of controls. In this case, there is only one
' control in each cell -- a TextBox control. To get its value,
' you copy the TextBox to a local instance (which requires casting)
' and extract its Text property.
'
' The first column -- Cells(0) -- contains the Update and Cancel buttons.
Dim tb As TextBox

' Gets the value the TextBox control in the third column
tb = CType(e.Item.Cells(1).Controls(0), TextBox)
fName = tb.Text

' Gets the value the TextBox control in the fourth column
tb = CType(e.Item.Cells(3).Controls(0), TextBox)
lName = tb.Text

' Finds the row in the dataset table that matches the
' one the user updated in the grid. This example uses a
' special Find method defined for the typed dataset, which
' returns a reference to the row.
Dim r As dsCategories1.employeeRow

r = DsCategories1.employee.FindByemp_id(key)

' Updates the dataset table.
r.fname = fName
r.lname = lName

' Calls a SQL statement to update the database from the dataset
OleDbDataAdapter1.Update(DsCategories1)

' Takes the DataGrid row out of editing mode
DataGrid1.EditItemIndex = -1

' Refreshes the grid
DataGrid1.DataBind()

End Sub
fbysss 2004-03-08
  • 打赏
  • 举报
回复
我倒,几个月后来看居然没人回答,谁要分,来顶一下!

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧