再次抱歉,专家再次打扰。但是
我们有一个名为 orderdate 的数据库日期。
如果今天的日期 - orderdate 少于 2 天(或 48 小时),请禁用Cancel Order
按钮,以便用户无法取消他或她的订单。
当我尝试运行以下代码时,我得到Input string not in the format
Orderdate 是日期时间类型。但是,我们希望以 MM/dd/yyyy 的格式显示日期。示例:2013 年 6 月 4 日,而不是 2013 年 6 月 4 日。
你能看看我的代码并告诉我我做错了什么吗?
If dr1.Read() Then
Dim odate As String = DateTime.Parse(dr1("orderDates").ToString()).ToShortDateString()
Dim cancelBtn As New Button()
Dim dates As String = DateTime.Parse(Now().ToString()).ToShortDateString()
If (sdate - dates) <2 Then
cancelBtn.Enabled = False
Else
cancelBtn.Enabled = True
End If
End If
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
' Create cancel training button
Dim cancelBtn As New Button()
cancelBtn.Style.Add("width", "105px")
cancelBtn.Style.Add("padding", "5px")
cancelBtn.Style.Add("margin", "5px")
'cancelBtn.Enabled = False
cancelBtn.Text = "Cancel training"
If e.Row.RowIndex > "-1" Then
' Change tracking ID to link
'Dim track As [String] = e.Row.Cells(4).Text
'If track <> " " AndAlso track.Length > 0 Then
' Dim trackLink As New Literal()
' trackLink.Text = "<a style='color: blue;' href='" + track + "'/>Track</a>"
' e.Row.Cells(4).Controls.Add(trackLink)
'End If
' Add buttons to column
Dim oid As [String] = e.Row.Cells(0).Text
Dim invoiceLink As New Literal()
invoiceLink.Text = "<a style='color: blue;' href='Invoice.aspx?oid=" + oid + "'/>" + oid + "</a>"
e.Row.Cells(0).Controls.Add(invoiceLink)
e.Row.Cells(e.Row.Cells.Count - 1).Controls.Add(cancelBtn)
' Pass order id & row to on-click event
'cancelBtn.Click += new EventHandler(this.cancelBtn_Click);
'cancelBtn.CommandArgument = e.Row.RowIndex + "-" + oid
End If
End Sub