I am new to asp.net and c# and have to deal with the event handling for a dynamically created table. The Background:
I have a method in my code-behind CSS file and there, I create dynamically a table to show users in the first column and for every user, I have a checkbox in the second column. My table is displayed well, so the creation is not the problem.
My problem is, that I need event-handling. The goal is, to "mark" users by clicking their appropriate checkbox and then to do, whatever I should do with such users.
I have added the code for event handling with "+=" and I have also tried to use an event handler object. But the problem is: my event-handling code is never reached (i checked this by running and debugging the code).
I'm totally new to asp.net and c# and HTML, javascript and so on. So i don't know much about page-life-cycle and things like that. And it will last time, to get in, cause im a student and I'm just working 2 days a week. If anybody can explain me, how I can do event handling in c# and asp.net for dynamically created elements, that would help me much. Thanks for every help :)
foreach (ListItem li in list_deletedUsers.Items)
{
String s = li.Text;
//Creating the basic Elements
TableRow myrow = new TableRow();
TableCell cellone = new TableCell();
TableCell celltwo = new TableCell();
CheckBox cb = new CheckBox();
//cb.CheckedChanged += cb_CheckedChanged;
//cb.CheckedChanged += this.cb_CheckedChanged;
//cb.CheckedChanged += new
System.EventHandler(cb_CheckedChanged);
//Setting the values and adding cells to row
cellone.Text = s;
myrow.Cells.Add(cellone);
celltwo.Controls.Add(cb);
celltwo.ApplyStyle(tableStyle);
myrow.Cells.Add(celltwo);
//Third Column Cell for further use
//TableCell cellthree = new TableCell();
//cellthree.BackColor = System.Drawing.Color.AliceBlue;
//Adding to Row
//myrow.Cells.Add(cellthree);
//Adding to TableBert
TableBert.Rows.Add(myrow);
}
Here in this methode i create the table:
public void rbe_changed(object sender, EventArgs e)
{
//do some stuff
//look for the user list
//create the table like i show above
}