日期:2014-05-19  浏览次数:20496 次

循环调用控件
页面有多个相同的Dropdownlist用来设定查询的条件,
各个Dropdownlist的取值按照数字进行编号,如ddl0,ddl1,ddl2,ddl3…
如果在后台编写代码时,如果循环获取相应的控件?
例如:
for(int   i=0;   i <n;   i++)
通过i的变化来获得对相应控件的调用并进行操作?

------解决方案--------------------
DropDownList ddl0 = this.FindControl( "ddl0 ") as DropDownList
if(ddl0 != null)
{
//.....
}
------解决方案--------------------
for(int i=0; i <n; i++)
{
DropDownList ddl = FindControl( "ddl "+i.ToString()) as DropDownList;
}