2 回答

TA貢獻1865條經(jīng)驗 獲得超7個贊
protected void Page_Load(object sender, EventArgs e)
{
CheckBox chk = new CheckBox();
chk.Text = "testall"; // 這里可以換成數(shù)據(jù)庫的內(nèi)容
chk.CheckedChanged += new EventHandler(chk_CheckedChanged);
chk.AutoPostBack = true;
Page.Form.Controls.Add(chk);
for (int i = 0; i < 10; i++)
{
CheckBox chk2 = new CheckBox();
chk2.Text = "test" + i.ToString(); // 這里可以換成數(shù)據(jù)庫的內(nèi)容
chk2.Checked = (i % 3 == 0); // 這里可以換成數(shù)據(jù)庫的內(nèi)容
Page.Form.Controls.Add(chk2);
}
}
void chk_CheckedChanged(object sender, EventArgs e)
{
CheckBox all = sender as CheckBox;
foreach(Control ctl in Page.Form.Controls)
{
if (ctl is CheckBox)
{
CheckBox chk = ctl as CheckBox;
chk.Checked = all.Checked;
}
}
}
- 2 回答
- 0 關(guān)注
- 1399 瀏覽
添加回答
舉報