动态加载的问题
protected void Button1_Click(object sender, EventArgs e) //点击获取值
{
foreach (System.Web.UI.Control ctl in Page.Form.Controls)
{
if (ctl is CheckBox)
{
CheckBox chk = ctl as CheckBox;
if (chk.Checked == true)
{
Response.Write(chk.Text);
}
}
}
}
protected void btn_Click(object sender, EventArgs e) //点击加载
{
int j = 5;
for (int i = 1; i <= j; i++)
{
CheckBox cb = new CheckBox();
cb.Text = i.ToString();
cb.Font.Size = System.Web.UI.WebControls.FontUnit.Small;
cb.ID = "cb" + i.ToString();
cb.Checked = false;
Page.Form.Controls.Add(cb);
}
}
获取不到值,在线等
------解决方案--------------------
他的意思是点击加载时得到5个checkbox,再选中一个或多个得到选中checkbox的值
------解决方案--------------------
C# code
override protected void OnInit(EventArgs e)
{
//重新执行动态加载控件的方法
}