0
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 GOT FALSE VALUE
            	{
	            //processing check boxes	
		}
	}
}

Edited by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by __avd
0

>i get false value of checkbox

Don't use IsPosback.

protected void Page_Load(object sender, EventArgs e)
{
		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;
		}
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.