CheckBox chk=new CheckBox();
chk.AutoPostBack = true;
chk.CheckedChanged += new EventHandler(chk_CheckedChanged);
tbcell3.Controls.Add(chk);
tbrow1.Cells.Add(tbcell3);
tbl.Controls.Add(tbrow1);
this.Controls.Add(tbl);
like this the check box was created dynamically now i want to write the code in chk_checkedchanged event,i tried with the bellow code it's working fine
void chk_CheckedChanged(object sender, EventArgs e)
{
tbl.BackColor = Color.Black;
}
if if kept the above code in for loop like bellow
for(int i=0;i<3;i++)
{
hi i created one check box dynamically and added to table like bellow
CheckBox chk=new CheckBox();
chk.AutoPostBack = true;
chk.CheckedChanged += new EventHandler(chk_CheckedChanged);
tbcell3.Controls.Add(chk);
tbrow1.Cells.Add(tbcell3);
tbl.Controls.Add(tbrow1);
this.Controls.Add(tbl);
}
Then on the form 3 check box controls will be created , and the checked changed event was working for the last check box, but i want the checked changed event should work for every check box wich is created dynamically with the above code
DRISHTYPosted May 20, 2010, 4:41 AM
I tried the code, that you have mentioned. There is no problem in that. Its working fine at my end.
May be the problem is due to some other code.
Please mark answer as accepted if it solves your problem. So that if someone else have similar problem so they can refer that answer.
Like You have used solution mentioned in my reply from your last post.
Thanks