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

fbysss 2003-09-11 10:40:59
DataGrid1_EditCommand中编辑的代码:
DataGrid1.EditItemIndex = e.Item.ItemIndex;
DataGrid1.DataBind();
我希望不通过写SQL语句,达到更新的效果,同时DATAGRID也刷新数据。
...全文
78 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
  • 打赏
  • 举报
回复
我倒,几个月后来看居然没人回答,谁要分,来顶一下!
注意: chm格式文档如果打不开,有可能是被杀毒软件拦截掉了,请关闭后再试,如果还是不能用,就使用exe格式的吧!另外文档全部存放在docs目录下,有些人自己不知道看文档,也不知道看下载说明,甚至连翻目录都懒得翻,就评论说根本没有文档,骗人什么的,对于你们我真的很不屑。 jQuery EasyUI 1.4.1版本更新内容: Bug(修复) combogrid:修复combogrid组件和其他combo组件高度不一致的问题datagrid:修复在datagrid行元素调用“updateRow”方法的时候丢失某些类样式的问题; menubutton:修复在被禁用的按钮上使用“enable”方法无效的问题; form:修复在form组件中调用“clear”方法以后导致firebox组件失效的问题。 Improvement(改进) tabs:“update”方法增加“type”参数,允许用户更新表头、表体或整个tab控件; panel:添加“openAnimation”、“openDuration”、“closeAnimation”和“closeDuration”属性用来设置面板打开和关闭时的动画效果; panel:添加“footer”属性用来定义在页脚展示的页脚栏; datagrid:调用“endEdit”方法可正确获取编辑值(这应该是一个已有功能的改进,具体内容不得而知); datagrid:添加“onBeforeSelect”、“onBeforeCheck”、“onBeforeUnselect”和“onBeforeUncheck”事件; propertygrid:允许用户使用“beginEdit”方法进行行编辑; datebox:添加“cloneFrom”方法来快速创建“datebox”组件; datetimebox:添加“cloneFrom”方法来快速创建“datetimebox”组件。
注意: chm格式文档如果打不开,有可能是被杀毒软件拦截掉了,请关闭后再试,如果还是不能用,就使用exe格式的吧!另外文档全部存放在docs目录下,有些人自己不知道看文档,也不知道看下载说明,甚至连翻目录都懒得翻,就评论说根本没有文档,骗人什么的,对于你们我真的很不屑。 jQuery EasyUI 1.4.1版本更新内容: Bug(修复) combogrid:修复combogrid组件和其他combo组件高度不一致的问题datagrid:修复在datagrid行元素调用“updateRow”方法的时候丢失某些类样式的问题; menubutton:修复在被禁用的按钮上使用“enable”方法无效的问题; form:修复在form组件中调用“clear”方法以后导致firebox组件失效的问题。 Improvement(改进) tabs:“update”方法增加“type”参数,允许用户更新表头、表体或整个tab控件; panel:添加“openAnimation”、“openDuration”、“closeAnimation”和“closeDuration”属性用来设置面板打开和关闭时的动画效果; panel:添加“footer”属性用来定义在页脚展示的页脚栏; datagrid:调用“endEdit”方法可正确获取编辑值(这应该是一个已有功能的改进,具体内容不得而知); datagrid:添加“onBeforeSelect”、“onBeforeCheck”、“onBeforeUnselect”和“onBeforeUncheck”事件; propertygrid:允许用户使用“beginEdit”方法进行行编辑; datebox:添加“cloneFrom”方法来快速创建“datebox”组件; datetimebox:添加“cloneFrom”方法来快速创建“datetimebox”组件。

62,047

社区成员

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

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

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

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