读书人

想用反射给页面中的一Label赋值解决思

发布时间: 2012-01-06 22:55:18 作者: rapoo

想用反射给页面中的一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);

读书人网 >asp.net

热点推荐