Asp.net 当执行搜索且未找到数据时,我们单击重置按钮并获取;对象引用未设置为对象的实例;。你知道为什么吗?
我们在搜索框中输入文本,单击搜索按钮 如果找到数据并单击“重置”按钮,您将优雅地返回搜索屏幕 如果未找到数据,并且您单击重置按钮,则应用程序将中断,并显示以下错误消息:Asp.net 当执行搜索且未找到数据时,我们单击重置按钮并获取;对象引用未设置为对象的实例;。你知道为什么吗?,asp.net,vb.net,Asp.net,Vb.net,我们在搜索框中输入文本,单击搜索按钮 如果找到数据并单击“重置”按钮,您将优雅地返回搜索屏幕 如果未找到数据,并且您单击重置按钮,则应用程序将中断,并显示以下错误消息: Object reference not set to an instance of an object. 此错误指向此行: Dim getAll As CheckBox = DirectCast(gridview1.HeaderRow _ .Cells(0).FindControl("getAll"), CheckBox)
Object reference not set to an instance of an object.
此错误指向此行:
Dim getAll As CheckBox = DirectCast(gridview1.HeaderRow _
.Cells(0).FindControl("getAll"), CheckBox)
这是标记:
<HeaderTemplate>
<asp:CheckBox ID="getAll" runat="server" onclick="getAllOf(this);CheckBox_getAll();" />
</HeaderTemplate>
有没有办法解决这个问题
这是我们最引人注目的应用之一
提前多谢尝试设置为true
听起来好像,当数据控件为空时,不会显示标题。因此,您的代码尝试访问标题行,并抛出一个错误,因为对象尚未初始化
或者你可以防止头不在那里的可能性:
Dim getAll As CheckBox
If gridview1.HeaderRow IsNot Nothing Then
getAll = DirectCast(gridview1.HeaderRow.Cells(0).FindControl("getAll"), CheckBox)
End If
当找不到数据时gridview1.HeaderRow是否存在?@ChidiOkeh真棒,很高兴我能帮上忙!
Dim getAll As CheckBox
If gridview1.HeaderRow IsNot Nothing Then
getAll = DirectCast(gridview1.HeaderRow.Cells(0).FindControl("getAll"), CheckBox)
End If