asp.net - Gridview 从数据库时间戳中删除毫秒
问题描述
我有一个Gridview
显示来自数据库的记录,包括时间戳。
在这种情况RowDataBound
下,我正在尝试检查时间戳以查看是否需要禁用按钮,但毫秒数被丢弃,因此我的比较无法正常工作。
如何保留从数据库到RowDataBound
事件的毫秒数?
我的代码:
Dim dt As New DataTable
Using cn = New SqlConnection(ConfigurationManager.AppSettings("MyConStr"))
cn.Open()
Dim cmd As SqlCommand = New SqlCommand("spGetRecords", cn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@FirstParm", FirstParm)
cmd.Parameters.AddWithValue("@SecondParm", SecondParm)
Using reader = cmd.ExecuteReader()
dt.Load(reader)
End Using
End Using
gvMyGrid.DataSource = dt
gvMyGrid.DataBind()
我的RowDataBound
:
Protected Sub gvMyGrid_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gvMyGrid.RowDataBound
If gvNotes.DataSource.Rows.Count > 0 Then
Dim someTime As DateTime = "03/18/2019 08:28:09.090"
If e.Row.Cells.Item(timestampIndex).Text = someTime 'This is never true because the cell text drops the milliseconds
'Disable button here...
End If
End If
End Sub
解决方案
推荐阅读
- c# - C# - 我的 ASP.NET MVC 页面总是向我的 JSON POST 请求返回 null
- linux - 如何在 Linux 终端中显示固定的文本行?
- azure - 使用管理员同意端点与使用 promt=consent 授权端点
- deno - 必须提供 --unstable 标志
- javascript - 循环遍历Java脚本中的表中的表
- amazon-web-services - 通过语音助手应用程序自定义付款
- plsql - 在 XML 中添加 [CDATA[ 元素
- django - 如何解决我的 Django 2.0 应用程序上的“Cookie csrftoken 将很快被拒绝,因为它的 sameSite 属性设置为无”警告?
- python - 我无法从 hdfs 加载数据,我使用 python pyarrow 库。在 docker 容器中
- amazon-web-services - 从 amazon cognito 获取所有数据