0
Reply

i cant access checkbox array variable on button click,object refrence error is occur

satish pawar

satish pawar

Jan 18 2010 8:00 AM
2.8k
public CheckBox[] cb = null;
int z=0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int count = (int)countcmd.ExecuteScalar();
Int32 k = Convert.ToInt32(Session["TZ"]);

cb = new CheckBox[count - k];

OleDbCommand cmd = new OleDbCommand("Select Member_Name from Member_Master", con);
dr = cmd.ExecuteReader();


while (dr.Read())
{

//creating check box


cb[z] = new CheckBox();
cb[z].Text = dr["Member_Name"].ToString();
Panel2.Controls.Add(cb[z]);
Panel2.Controls.Add(new LiteralControl("</br>"));
// if (z == (t - 1)) { Button6.Visible = true; }
z = z + 1;

}
}
}
protected void Button6_Click(object sender, EventArgs e)
{
//proccess to get the value of checked box and insert into database
cb[tzx] = new CheckBox();

for (int x = 0; x < cb.Length; x++)//ERROR OOCUR HERE
{
//cb[x] = new CheckBox();
if (cb[x].Checked == true)
{

//remain code..

}
}

}