Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public CheckBox[] cb = null;
int z=0;
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
        {
        cb = new CheckBox[count - k];
        //Database code.........
        while (dr.Read())//read data from access database
                {
            cb[z] = new CheckBox();
                    cb[z].Text = dr["Member_Name"].ToString();
                        Panel2.Controls.Add(cb[z]);
                        Panel2.Controls.Add(new LiteralControl("</br>"));
                        z = z + 1;
        }
    }
}
protected void Button6_Click(object sender, EventArgs e)
{
        for (int x = 0; x < cb.Length; x++)//ERROR IS HERE:Object reference not set to an instance of an object.
        {
        if (cb[x].Checked == true)//EVERY TIME I GOT FALSE VALUE RATHER I CHECKED BOXES
                {
                //processing check boxes    
        }
    }
}


[edit] Changed tag to C# [/edit]
Posted
Updated 18-Jan-10 21:54pm
v2

You are creating the checkboxes dynamically. These controls has to recreated each and every postback before accessing.

Read this[^] article for more details.
 
Share this answer
 
Remove if(!IsPostBack) condition
 
Share this answer
 

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