asp.net中 给控件批量赋值

本案例以给Literal控件批量赋值为例,同理,可为label、textbox等控件批量赋值
首先在前台将需要批量赋值的控件Literal的id设置成一定的规律,例如:Literal1、Literal2、Literal3、Literal4、Literal5....
int LiteralCount = GetLiteralCount(this);//获取Literal控件在本页面的数量
Literal la; //定义控件的类型为 Literal
for (int Literal_i = 0; Literal_i < LiteralCount; Literal_i++)
{
la = ((Literal)Page.FindControl("Literal" + Literal_i.ToString()));
la.Text = "你要赋的值";
}
参考资料:
获取某种控件在本页面的数量的方法:http://www.crazyming.cn/?p=158
版权声明:
作者:东明兄
链接:https://blog.crazyming.com/note/160/
来源:CrazyMing
文章版权归作者所有,未经允许请勿转载。


共有 0 条评论