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?
{
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;
}
}
}
你把foreach去掉试试