日期:2014-05-20  浏览次数:20824 次

动态添加的控件如何取其值
动态添加的控件如何取其值

for(int   i=0;i <9;i++)
{
checkbox   c=new   check();
this.controls.add(c);
}

然后如何取其值呢?
我一点取值按钮,上面添加的控件就消失了,在网了搜了半天,也没找到答案

------解决方案--------------------
this是哪个对象?

------解决方案--------------------
1:
checkbox c = new check()
c.checkedchanged += new EventHandler(cb_CheckedChanged)
void cb_CheckedChanged(..)
{
...
}
2:
foreach(checkbox tmp in this.controls)
{
...
}

------解决方案--------------------
生成:
for(i=0;i <10;i++)
{
RadioButtonList chkmc = new RadioButtonList();
chkmc.ID = "chkmc " + i.ToString();
myPanel.Controls.Add(chkmc);
}
取值:
string mcs= " ";
for (int i = 0; i < 10 ; i++)
{
if (Request.Form[ "chkmc " + i.ToString()] != null)
{
mcs += Request.Form[ "chkmc " + i.ToString()];
}
}
这是我之前写的,应该能用
------解决方案--------------------
for(int i = 0; i < 10; i++)
{
CheckBox cb = new CheckBox();
cb.Name = "CustomCb " + i;
this.Conttrols.Add(cb);
}

下面取值
for(int i = 0; i < 10; i++)
{
CheckBox cb = this.Controls.FindControl( "CustomCb " + i) as CheckBox;
bool checked = cb.Checked;
}
------解决方案--------------------
up