On button1 click i can add check boxes to the GridView column,
grid_student.DataSource = semDS;
grid_student.DataBind();
TemplateField tf = new TemplateField();
grid_student.Columns.Add(tf);
foreach (GridViewRow gr in grid_student.Rows)
{
CheckBox chk = new CheckBox();
chk.ID = "chkSelected";
chk.Checked=true;
gr.Cells[0].Controls.Add(chk);
}
But the problem is when i click on button2 it says that "object reference is not set to an instance of an object" code for button2
foreach (GridViewRow grr in grid_student.Rows)
{
if (grr.RowType == DataControlRowType.DataRow)
{
//CheckBox checkB = new CheckBox();
// checkB = grr.Cells[0].FindControl("chkSelected") as CheckBox;
CheckBox checkB =(CheckBox)grr.Cells[0].FindControl("chkSelected");
if (checkB.Checked)
{
Label78.Text = "True";//or whatever i want
}
}
}
actually i know this type of errors are mostly occurred when we are trying to take some null value into an object,
but in this case i have added check boxes successfully.
please reply,
it would be very helpful for me.
thanks in advance.