当前位置: 代码迷 >> ASP.NET >> Object reference not set to an instance of an object.该如何处理
  详细解决方案

Object reference not set to an instance of an object.该如何处理

热度:9195   发布时间:2013-02-25 00:00:00.0
Object reference not set to an instance of an object.
foreach(System.Web.UI.WebControls.DataGridItem   item   in   DataGrid1.Items)
{
CheckBox   ch=(CheckBox)item.FindControl( "selected ");
if   (ch.Checked==false)
{
ch.Checked=true;
}
}

exception   :
Object   reference   not   set   to   an   instance   of   an   object.  

where   is   the   error?  


------解决方案--------------------------------------------------------

foreach(System.Web.UI.WebControls.DataGridItem item in DataGrid1.Items)
{
CheckBox ch=(CheckBox)item.FindControl( "selected ");
if (ch != null) //判断ch有没有引用实例
{
if (ch.Checked==false)
{
ch.Checked=true;
}
}
}
------解决方案--------------------------------------------------------
断点监视一下看看 ch 的内容
  相关解决方案