我是asp.net和c#的新手,必须处理动态创建的表的事件处理。 背景:
我的代码隐藏CSS文件中有一个方法,在那里,我动态创建一个表来显示第一列中的用户,对于每个用户,我在第二列中有一个复选框。我的表格显示得很好,所以创建不是问题。
我的问题是,我需要事件处理。目标是,标记"用户通过单击相应的复选框然后执行操作,无论我应该如何处理此类用户。
我已使用" + ="添加了事件处理代码。我也尝试使用事件处理程序对象。但问题是:我的事件处理代码永远不会到达(我通过运行和调试代码来检查)。
我对asp.net和c#以及HTML,javascript等都是全新的。所以我不太了解页面生命周期和类似的东西。这将是最后一次,进入,导致我是一名学生,而我每周工作2天。如果有人可以解释我,我如何在c#和asp.net中为动态创建的元素进行事件处理,这对我有用。感谢您的帮助:)
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);
}
在这个方法中,我创建了表:
public void rbe_changed(object sender, EventArgs e)
{
//do some stuff
//look for the user list
//create the table like i show above
}