how to fire the checked changed event for all the checkboxes which r created dynamiclly an a aspx page

May 20 2010 2:31 AM
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);

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

Answers (1)