异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。来帮我看看啊

ljf820 2010-04-21 06:28:51
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误:


行 818: Dim cbox As CheckBox = Me.DataList1.Items(f).FindControl("CheckBox11")
行 819: If (Me.CheckBox10.Checked = True) Then
行 820: cbox.Checked = True
行 821: Else
行 822: cbox.Checked = False


源文件: c:\inetpub\wwwroot\网上购票系统\用户信息管理.aspx.vb 行: 820

堆栈跟踪:


[NullReferenceException: 未将对象引用设置到对象的实例。]
网上购票系统.WebForm7.CheckBox10_CheckedChanged(Object sender, EventArgs e) in c:\inetpub\wwwroot\网上购票系统\用户信息管理.aspx.vb:820
System.Web.UI.WebControls.CheckBox.OnCheckedChanged(EventArgs e)
System.Web.UI.WebControls.CheckBox.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent()
System.Web.UI.Page.RaiseChangedEvents()
System.Web.UI.Page.ProcessRequestMain() +1081
源代码如下:

Private Sub CheckBox10_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox10.CheckedChanged
Dim f As Integer
For f = 0 To Me.DataList1.Items.Count - 1
Dim cbox As CheckBox = Me.DataList1.Items(f).FindControl("CheckBox11")
If (Me.CheckBox10.Checked = True) Then
cbox.Checked = True
Else
cbox.Checked = False
End If


Next
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
Dim f, ji, i As Integer
Dim st As String
Me.SqlConnection1.Open()
For f = 0 To Me.DataList1.Items.Count - 1
If (CType(Me.DataList1.Items(f).FindControl("CheckBox11"), CheckBox).Checked) Then
st = "Delete from 留言表 where 编号=" & Int(CType(Me.DataList1.Items(f).FindControl("CheckBox11"), CheckBox).Text) & ""
Me.SqlCommand1 = New System.data.SqlClient.SqlCommand(st, Me.SqlConnection1)
Me.SqlCommand1.ExecuteNonQuery()
End If
Next
Me.SqlConnection1.Close()
BindDataList()
End Sub

设计页面代码有:
<asp:panel id="Panel2" style="Z-INDEX: 102; LEFT: 152px; POSITION: absolute; TOP: 1424px" Height="371px"
runat="server" Width="624px">
<P>
<asp:DataList id="DataList1" runat="server" ForeColor="#000040" Font-Size="XX-Small" Font-Names="宋体">
<FooterTemplate>
                                                   
</FooterTemplate>
<ItemTemplate>
<P>
<asp:CheckBox id=CheckBox11 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.编号") %>'>
</asp:CheckBox> 
<asp:Label id=Label1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.用户名") %>'>
</asp:Label>             </P>
<P>咨询主题:
<asp:Label id=Label5 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.咨询主题") %>'>
</asp:Label>    </P>
<P>
<asp:Label id=Label4 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.内容") %>'>
</asp:Label></P>
<P> </P>
<P>回复:
<asp:Label id=Label29 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.回复") %>'>
</asp:Label></P>
<P> </P>
<P>
<asp:Label id="Label2" runat="server">发表时间:</asp:Label>
<asp:Label id=Label3 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.发表时间") %>'>
</asp:Label></P>
<P>--------------------------------------------------------------                               </P>
</ItemTemplate>
<AlternatingItemTemplate>
<FONT face="宋体"></FONT>
</AlternatingItemTemplate>
<EditItemTemplate>
<FONT face="宋体"></FONT>
</EditItemTemplate>
</asp:DataList></P>
<P>
<asp:CheckBox id="CheckBox10" runat="server" Font-Size="XX-Small" Font-Names="宋体" AutoPostBack="True"
Text="选中所有的留言"></asp:CheckBox>  
<asp:Button id="Button11" runat="server" Font-Size="XX-Small" Font-Names="宋体" Text="删除选中的留言"></asp:Button>    
<asp:Button id="Button12" runat="server" Font-Size="XX-Small" Font-Names="宋体" Text="取消全选中的留言"></asp:Button>        </P>
<P>                      
 
<asp:LinkButton id="bp" runat="server" ForeColor="#000040" Font-Size="XX-Small" Font-Names="仿宋_GB2312">上一页</asp:LinkButton>            
<asp:LinkButton id="bn" runat="server" ForeColor="#000040" Font-Size="XX-Small" Font-Names="仿宋_GB2312">下一页</asp:LinkButton> </P>
<P>                      
<asp:TextBox id="TextBox1" Height="85px" runat="server" Width="216px" TextMode="MultiLine"></asp:TextBox></P>
<P>                                 
<asp:Button id="Button1" runat="server" ForeColor="#400000" Font-Size="Small" Font-Names="仿宋_GB2312"
Text="回复" BackColor="Silver" BorderStyle="Outset"></asp:Button>                
</P>
<P> </P>
</asp:panel>
...全文
111 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljf820 2010-04-21
  • 打赏
  • 举报
回复
那要怎么办啊
捷哥1999 2010-04-21
  • 打赏
  • 举报
回复
应该是这个控件没有找到:

Dim cbox As CheckBox = Me.DataList1.Items(f).FindControl("CheckBox11")

导致了cbox为null
所以这句代码导致了异常:System.NullReferenceException: 未将对象引用设置到对象的实例。

If (Me.CheckBox10.Checked = True) Then


16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧