选择复选框的编码错误 [英] error in coding of selecting checkbox

查看:87
本文介绍了选择复选框的编码错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误:-
对象引用未设置为对象的实例.

源错误:

Error:-
Object reference not set to an instance of an object.

Source Error:

CheckBox cBox = (CheckBox)contact.FindControl("cbSelect");  //here it gives error...
           if (cBox.Checked)
           {



请帮助我解决此错误.....



Plz Help me to solve this error.....

推荐答案

对象引用未设置为对象的实例
当您尝试使用属性或调用对象的方法为null时,会发生此错误.更多详细信息:此处 [
Object reference not set to an instance of an object
This error happens when you try to use a property or call a method of an object that is null. More details: here[^]

A simple use of Visual studio DEBUGGER can tell you the object because of which it is happening. Just look at the stack trace and put a debugger on that line. Check the objects of that line and see if any one is null and you are trying to use that objects property. Handle the same.


For now, error in line below
CheckBox cBox = (CheckBox)contact.FindControl("cbSelect");


表示在"contact"对象中没有名为"cbSelect"的控件. contact.FindControl("cbSelect")返回了null.现在,当您尝试将其转换为CheckBox时,会引发错误.

验证名称正确并且存在于控制对象联系人中.还要进行空检查.


means that there was no control named ''cbSelect'' in the ''contact'' object. contact.FindControl("cbSelect") returned null. Now, when you try to cast it into CheckBox, it throw error.

Verify that the name is correct and exists in the control object contact. Put a null check too.




首先,让我告诉您一件事,您的代码无法找到您的控件.什么是联系"?任何占位符或任何面板或任何形式?

按照给出的链接找到您的答案:
http://odetocode.com/articles/116.aspx [ http://msdn.microsoft.com/en-us/library/486wc64h.aspx [ ^ ]

一切顺利.
Hi,

First of all let me tell you one thing that your code is unable to find your control. What is "contact" actually? any place holder or any panel or any form?

Follow the links given to find your answer:
http://odetocode.com/articles/116.aspx[^]
http://msdn.microsoft.com/en-us/library/486wc64h.aspx[^]

All the best.


这篇关于选择复选框的编码错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆