更新工作,除非我检查某个复选框,然后datetime.now.ToString抛出错误

时间:2014-09-26 17:41:42

标签: checkbox nullreferenceexception formview

我希望能够在我的formview中的行更新时加上时间戳,只有在我不检查PendingBit复选框时才会有效。我已经尝试了一天半来解决这个问题,但我是新手,我真的很感激一些帮助。由于此错误非常通用,因此我很难找到适合我情况的任何内容。

这里的错误:对象引用没有设置为对象的实例

令人讨厌的代码行是:      UpdDate.Text = DateTime.Now.ToString(" yyyy-MM-dd hh:mm:ss tt")

完整的事件代码是:       受保护的子FormView1_DataBound(发件人为对象,e为EventArgs)处理FormView1.DataBound

If FormView1.CurrentMode = FormViewMode.Edit Then
  Dim UpdDate As TextBox = TryCast(FormView1.FindControl("UpdDateTextBox"), TextBox)
  'line below updates update textbox on formview before page reloads but causes object reference not set to an instance of the object
  UpdDate.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt")

  '''' UpdDate.Text = TryCast(FormView1.FindControl("label2"), Label).ToString()


  Response.Write("DataBound")
End If

End Sub

如果您需要后面代码中的标记或其他代码,请告诉我。除非你提出要求,否则我不想让你破坏我的​​所有代码。

谢谢! 附: C#代码很好。我可以将它转换为VB

0 个答案:

没有答案
相关问题