I'm adding checkbox controls dynamically in asp.net gridview like this:
CheckBox cb1 = new CheckBox();
cb1.Text = row.Cells[3].Text;
row.Cells[3].Controls.Add(cb1);
And I want to access whether that checkbox is checked or not on button click event...
on button click I have tried this:
foreach (GridViewRow item in grdreport.Rows)
{
if (item.RowType == DataControlRowType.DataRow)
{
CheckBox checkbox1 = (CheckBox)item.FindControl("cb1");
// cb1.Checked = true;
if (checkbox1.Checked)
{
}
}
}
but it gives me an error:
Object reference not set to an instance of an object cb1 value is null