Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 当执行搜索且未找到数据时,我们单击重置按钮并获取;对象引用未设置为对象的实例;。你知道为什么吗?_Asp.net_Vb.net - Fatal编程技术网

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