我正在尝试在单击按钮时从动态创建的复选框中读取。问题是,一旦选中了复选框,在提交点击时就无法正确读取进一步的取消选中操作。
编辑:复选框最初是通过调用SetSelection
如图所示在选择单选按钮列表时创建的。
代码片段如下所示,知道可能是什么问题吗?
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
{
..
GenerateDynamicUI();
}
...
}
private void GenerateDynamicUI(int selectedItem)
{
...
TableCell cellCheckBox = new TableCell();
CheckBox chkBox = new CheckBox();
chkBox.Text = "Consider all";
chkBox.ID = "chkAll";
cellCheckBox.Controls.Add(chkBox);
TableRow chkRow = new TableRow();
chkRow.Cells.Add(cellCheckBox);
table.Rows.Add(chkRow);
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
...
bool isChecked = ((CheckBox)table.FindControl("chkAll")).Checked;
}
private void SetSelection()
{
int selectedItem = int.Parse(radiobuttonList.SelectedItem.Value);
GenerateDynamicUI(selectedItem);
pnlDynamic.Visible = true;
}
protected void radiobuttonList_SelectedIndexChanged(object sender, EventArgs e)
{
SetSelection();
}