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 的内容