修改gridview更新操作以将时间放入列中?
我有一个包含 3 列的 gridview,只有一列将由用户编辑。每当编辑它时,我想将其他列之一设置为当前时间。如果您愿意的话,可以输入“上次更新时间”。可能的?
I have a gridview with 3 columns, only one column is going to be edited by the user. Whenever it is edited I'd like to set one of the other columns to the current time. A "time last updated" if you will. Possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
安迪的解决方案有效。
另一种方法是更改与网格关联的 UPDATE sql 语句。在 UPDATE 语句中使用 GetDate() (或您的数据库等效项),如下所示:
UPDATE MyTable SET usereditvalue = @usereditvalue, mytimestamp = GETDATE()
可选地使用Where语句:
WHERE MyTable.ID = @oldIDvalue
要这样做,请阅读参数化查询和 gridview / 表键值(用于 WHERE 语句)。
Andy's solution works.
Another method would be to alter the UPDATE sql statement that is associated with the grid. Use GetDate() (or your DB equivalent) in the UPDATE statement like so:
UPDATE MyTable SET usereditvalue = @usereditvalue, mytimestamp = GETDATE()
Optionally with a Where statement:
WHERE MyTable.ID = @oldIDvalue
For doing it this way, read up on parameterized queries and gridview / table keyvalues (for your WHERE statement).
将事件处理程序添加到网格视图,如下所示。
此方法假设有一系列可以编辑的列,由 lowerBound 和 upperBound 定义。现在,每当修改单元格时,如果该单元格位于该范围内,则由 columnNumberWithTimes 定义的列中相应行中的单元格将使用新时间进行更新。
Add an event handler to the grid view like so
This method assumes that there is a range of columns that can be edited, defined by lowerBound and upperBound. Now, whenever a cell is modified, if that cell lies within that range, a cell in that respective row in a column defined by columnNumberWithTimes will be updated with the new time.