如何修复“对象引用未设置为对象实例”的错误。它指的是哪个对象?
代码:Private Sub dvSMasterCurrentYear_DataBound(sender As Object, e As EventArgs) Handles dvSMasterCurrentYear.DataBound
Dim dv As DetailsView = New DetailsView
If DetailsViewMode.Insert Then
DirectCast(dv.FindControl("PlantYear"), TextBox).Text = GetYear()
End If
End Sub
GetYear返回当前年份,它显示在DetailsView文本框“PlantYear”中。我尝试使用以上代码插入该值。
感谢您的帮助。
FindControl
返回null/Nothing。如果它这样做,那么代码将抛出NRE异常。 - Ňɏssa Pøngjǣrdenlarp