当前位置: 代码迷 >> ASP.NET >> Web 控件的使用解决思路
  详细解决方案

Web 控件的使用解决思路

热度:8272   发布时间:2013-02-25 00:00:00.0
Web 控件的使用
现在在作一个项目,用到在web页面上自动添加控件,我想可用两种方式实现:
1.一种是实例化Web控件,然后在服务期端添加到Web页面上,如:
RadioButtonList   ral   =   new   RadioButtonList();
for(int   i=0;i <1000;i++)
{
ListItem   item   =   new   ListItem();
item.Text   =   "aaa "   +   i.ToString();
ral.Items.Add(item);
}
this.Controls.Add(ral);

2.在服务器端组织html代码,发送到客户端,如:
string   str;
for(int   i=0;i <1000;i++)
{
str+= " <input   type=Radio   name=aaa   id= 'aaa "   +   i.ToString();   + " '   > <label   for= 'aaa "   +   i.ToString();+ " '> aaa "+i.ToString();   + " </label> ";
}
Response.Write   str;

这两种方式那种方式更好,效率更高一些呢??


------解决方案--------------------------------------------------------
2效率高。

1可读性高。

自己取舍
------解决方案--------------------------------------------------------
第二种

第一种的话会添加一些额外的HTML代码的
------解决方案--------------------------------------------------------
2好点
------解决方案--------------------------------------------------------
其实lz可以进行一个测试,看看到底是哪个效率更高一点~~~
  相关解决方案