Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
8 line is giving error. Can any one help me here?

private void GetOldValues()
        {
            ArrayList arr;
            if (Session["SelectedRecords"] != null)
                arr = (ArrayList)Session["SelectedRecords"];
            else
                arr = new ArrayList();
            //Giving me an error "Object reference not set to an instance of an object." 
            CheckBox chkAll = (CheckBox)gvManageJob.HeaderRow
                                 .Cells[0].FindControl("SelectAll");
            for (int i = 0; i < gvManageJob.Rows.Count; i++)
            {
                if (chkAll.Checked)
                {
                    if (!arr.Contains(gvManageJob.DataKeys[i].Value))
                    {
                        arr.Add(gvManageJob.DataKeys[i].Value);
                    }
                }
                else
                {
                    CheckBox chk = (CheckBox)gvManageJob.Rows[i]
                                       .Cells[0].FindControl("chkdelete");
                    if (chk.Checked)
                    {
                        if (!arr.Contains(gvManageJob.DataKeys[i].Value))
                        {
                            arr.Add(gvManageJob.DataKeys[i].Value);
                        }
                    }
                    else
                    {
                        if (arr.Contains(gvManageJob.DataKeys[i].Value))
                        {
                            arr.Remove(gvManageJob.DataKeys[i].Value);
                        }
                    }
                }
            }
            Session["SelectedRecords"] = arr;

        }


Thanks in advnance


[Agen_Spock]
- Changed Question heading
Posted
Updated 15-Jul-14 22:46pm
v2

1 solution

Use debugger, set a breackpoint to the line

C#
CheckBox chkAll = (CheckBox)gvManageJob.HeaderRow


and watch the variable gvManageJob - it seems to be null.
 
Share this answer
 
v3
Comments
agent_kruger 16-Jul-14 4:45am    
+5 vote, this error is specifically shown for null values.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900