winform c# 用checkbox 如何实现多选然后统计数据

如题所述

第1个回答  推荐于2016-01-08
protected void Page_Load(object sender, EventArgs e)
{
CheckBox chk = new CheckBox();
chk.Text = "testall"; // 这里可以换成数据库的内容
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(); // 这里可以换成数据库的内容
chk2.Checked = (i % 3 == 0); // 这里可以换成数据库的内容
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个回答  2015-03-09
在 checkbox 的 onchange 时间中 重新计算统计本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网