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

ljf820 2010-04-20 02:01:51
源错误:


行 835: Dim cbox As CheckBox = Me.DataList1.Items(f).FindControl("CheckBox11")
行 836: If (Me.CheckBox10.Checked = True) Then
行 837: cbox.Checked = True
行 838: Else
行 839: cbox.Checked = False

堆栈跟踪:


[NullReferenceException: 未将对象引用设置到对象的实例。]
网上购票系统.WebForm7.CheckBox10_CheckedChanged(Object sender, EventArgs e) in c:\inetpub\wwwroot\网上购票系统\用户信息管理.aspx.vb:837
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



...全文
251 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljf820 2010-04-21
  • 打赏
  • 举报
回复
<asp:panel id="Panel2" style="Z-INDEX: 102; LEFT: 152px; POSITION: absolute; TOP: 1424px" Width="624px"
runat="server" Height="371px">
<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>
ljf820 2010-04-21
  • 打赏
  • 举报
回复
有啊 有ID为CheckBox11的checkbox
ljf820 2010-04-21
  • 打赏
  • 举报
回复
If cbox IsNot Nothing Then

End If
用这个语句错误啊 我是用VB的
criedshy 2010-04-21
  • 打赏
  • 举报
回复
有没有ID为CheckBox11的checkbox?
ljf820 2010-04-21
  • 打赏
  • 举报
回复
显然这个不存在
Me.DataList1.Items(f).FindControl("CheckBox11")
这个是存在的
Me.DataList3.Items(f).FindControl("CheckBox3")
为什么啊?我代码都一样啊

wuyq11 2010-04-20
  • 打赏
  • 举报
回复
If cbox IsNot Nothing Then

End If
appleller 2010-04-20
  • 打赏
  • 举报
回复
显然这个不存在
Me.DataList1.Items(f).FindControl("CheckBox11")
这个是存在的
Me.DataList3.Items(f).FindControl("CheckBox3")
ljf820 2010-04-20
  • 打赏
  • 举报
回复
哪位高手 帮帮我把
ljf820 2010-04-20
  • 打赏
  • 举报
回复
怎么看啊 能不能说明白点 我是菜鸟哦
Alden 2010-04-20
  • 打赏
  • 举报
回复
看看checkbox是否被实例化了
ljf820 2010-04-20
  • 打赏
  • 举报
回复
我把 '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
注释掉
再运行,错误提示
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误:


行 847: Me.SqlConnection1.Open()
行 848: For f = 0 To Me.DataList1.Items.Count - 1
行 849: If (CType(Me.DataList1.Items(f).FindControl("CheckBox11"), CheckBox).Checked) Then
行 850: st = "Delete from 留言表 where 编号=" & Int(CType(Me.DataList1.Items(f).FindControl("CheckBox11"), CheckBox).Text) & ""
行 851: 'st = st + CType(Me.DataList1.Items(f).FindControl("Label1"), Label).Text


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

堆栈跟踪:


[NullReferenceException: 未将对象引用设置到对象的实例。]
网上购票系统.WebForm7.Button11_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\网上购票系统\用户信息管理.aspx.vb:849
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain() +1277


ljf820 2010-04-20
  • 打赏
  • 举报
回复
要怎么检查啊?是在Dim cbox As CheckBox = Me.DataList1.Items(f).FindControl("CheckBox11")
上面输入DataList1.Items(f). 看看能不能找到 CheckBox1 吗 我试了 没有
CloneCenter 2010-04-20
  • 打赏
  • 举报
回复
Dim cbox As CheckBox = Me.DataList1.Items(f).FindControl("CheckBox11")

这句话的代码,查找的结果 cbox 为空引用(Nothing),检查 DataList1.Items(f) 中是否包含 CheckBox1 控件。
zsuswy 2010-04-20
  • 打赏
  • 举报
回复
Dim cbox As CheckBox = Me.DataList1.Items(f).FindControl("CheckBox11")
------
你看下你这个在什么事件后面,有可能因为事件顺序的关系,这个CheckBox还没有创建。
yzzd2167 2010-04-20
  • 打赏
  • 举报
回复
遍歷一下 看看 Me.DataList1.Items(f) 中有沒有 "CheckBox11" 這個物件
ljf820 2010-04-20
  • 打赏
  • 举报
回复
我在同一个页面的不同面板里也实现了同样的功能
Private Sub CheckBox6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox6.CheckedChanged
Dim f As Integer
For f = 0 To Me.DataList3.Items.Count - 1
Dim cbox As CheckBox = Me.DataList3.Items(f).FindControl("CheckBox3")
If (Me.CheckBox6.Checked = True) Then
cbox.Checked = True
Else
cbox.Checked = False


End If
Next
End Sub
运行的时候就没有问题啊
水哥阿乐 2010-04-20
  • 打赏
  • 举报
回复
CheckBox没有实例化,可以需要New一下

16,553

社区成员

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

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