我正在开发一个应用程序在C#中,我使用datagridview和gridview第一列包含复选框,我想chech复选框是真实的或不是,但它给了我'对象引用未设置为对象的实例'。代码如下检查gridview列复选框
private void btnDelete_Click(object sender, EventArgs e)
{
StudentDAL s = new StudentDAL();
try
{
for (int i = 0; i < this.dataGridView1.RowCount; i++)
{
if (!DBNull.Value.Equals(this.dataGridView1.Rows[i].Cells[0]) && (bool)this.dataGridView1.Rows[i].Cells[0].Value == true)
{
s.delete(Convert.ToInt32(this.dataGridView1.Rows[i].Cells[1].Value));
i--;
}
}
this.dataGridView1.DataSource = s.getAll();
}
catch (Exception nn)
{
}
}
请帮帮我。
你应该用'先拿到CheckBox控件FindControl()'方法,然后检查它是否被检查 –