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

想用反射给页面中的一Label赋值
页面中有数Label,分别叫做lb1,lb2...lb10
cs中:
for(int   i=1;i <11;i++){
labelName= "lb "+i;
//这里用拼好的labelName反射,得到页面中对应的Label,并将其赋值,怎么写?
}

只想用反射实现

------解决方案--------------------
System.Type type = typeof(System.Web.UI.WebControls.Label); System.Reflection.PropertyInfo p= type.GetProperty( "Text "); string sText = p.GetValue(this.FindControl( "Label1 "),null).ToString(); Response.Write(sText);