asp.net如何循环对checkbox检查及取值~~~~~~~~~~~~~~急!!!!!!!!~~~~~~~~~
我现在有60个CheckBox控件,要做判断并取值,并且控件名称是有规律的
我的是从CheckBox1,CheckBox2,CheckBox3...CheckBox60
请高手没给个办法吧 !!!!!!!!
以下代码判断并获取不了值
急呀~~~~~~~~~~~~~~~~~~~~
protected void Button2_Click(object sender, EventArgs e)
{
string str;
for (int i = 1; i <= 60; i++)
{
if (Checkbox(i).check == true)
{
str = str + Checkbox(i).Text;
}
}
}
------解决方案--------------------protected void Button2_Click(object sender, EventArgs e)
{
string str;
for (int i = 1; i <= 60; i++)
{
Checkbox cb = Page.FindControl( "Checkbox "+i) as Checkbox ;
if (cb != null && cb.check == true)
{
str = str + cb.Text;
}
}
}
------------------
试试