我正在開發一個應用程序在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()'方法,然後檢查它是否被檢查 –